Skip to content

Commit

Permalink
feat: table component
Browse files Browse the repository at this point in the history
* feat: add numeric sort to id column in story
  • Loading branch information
bariskaraca committed Jan 31, 2024
1 parent dcfe2bf commit 107b9cb
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/components/table/bl-table.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,27 @@ export const TableTemplate = (args, {id}) => {
});

}
let {data, headers, selectValue} = args;
let {data, headers, selectValue, sortedData} = args;
const tableData = sortedData || data;
const onSort = (event) => {
const [sortKey, sortDirection] = event.detail;
console.log("onSort", event.detail);
const columnType = sortKey==="id" ? "number" : "string";
updateArgs({
...args,
data: data.sort((a, b) => {
return a[sortKey].toString().localeCompare(b[sortKey], 'tr', {sensitivity: 'base'}) * (sortDirection === 'asc' ? -1 : 1);
}),
sortedData: (sortKey&&sortDirection)? [...data].sort((a, b) => {
if (columnType === 'string') {
return a[sortKey].localeCompare(b[sortKey], 'tr', { sensitivity: 'base' }) * (sortDirection === 'asc' ? -1 : 1);
}
if (a[sortKey] < b[sortKey]) {
return sortDirection === 'asc' ? -1 : 1;
}
if (a[sortKey] > b[sortKey]) {
return sortDirection === 'asc' ? 1 : -1;
}
return 0;
}) : [...data],
});

console.log(data)
}
const onRowSelect = (event) => {
console.log("onRowSelect", event.detail);
Expand Down Expand Up @@ -73,7 +82,7 @@ export const TableTemplate = (args, {id}) => {
</bl-table-row>
</bl-table-header>
<bl-table-body>
${data.map((row) =>
${tableData.map((row) =>
html`
<bl-table-row selection-key="row-${row.id}">
${headers.map((header, col_idx) =>
Expand Down

0 comments on commit 107b9cb

Please sign in to comment.