fix sorting table list

This commit is contained in:
rizky 2024-07-16 22:40:43 -07:00
parent 2ae5e5e90b
commit 56207c33fd
2 changed files with 33 additions and 27 deletions

View File

@ -28,6 +28,7 @@ import { filterWhere } from "../filter/parser/filter-where";
import { getFilter } from "../filter/utils/get-filter"; import { getFilter } from "../filter/utils/get-filter";
import { Skeleton } from "../ui/skeleton"; import { Skeleton } from "../ui/skeleton";
import { sortTree } from "./utils/sort-tree"; import { sortTree } from "./utils/sort-tree";
import { set } from "lib/utils/set";
type OnRowClick = (arg: { type OnRowClick = (arg: {
row: any; row: any;
@ -151,8 +152,13 @@ export const TableList: FC<TableListProp> = ({
local.sort.columns = cols; local.sort.columns = cols;
local.paging.skip = 0; local.paging.skip = 0;
if (cols.length > 0) { if (cols.length > 0) {
const { columnKey, direction } = cols[0]; let { columnKey, direction } = cols[0];
if (columnKey.includes(".")) {
let root: any = {};
set(root, columnKey, direction === "ASC" ? "asc" : "desc");
local.sort.orderBy = root;
} else {
let should_set = true; let should_set = true;
const gf = JSON.stringify(gen_fields); const gf = JSON.stringify(gen_fields);
const fields = fields_map.get(gf); const fields = fields_map.get(gf);
@ -186,6 +192,7 @@ export const TableList: FC<TableListProp> = ({
[columnKey]: direction === "ASC" ? "asc" : "desc", [columnKey]: direction === "ASC" ? "asc" : "desc",
}; };
} }
}
} else { } else {
local.sort.orderBy = null; local.sort.orderBy = null;
} }
@ -417,7 +424,7 @@ export const TableList: FC<TableListProp> = ({
row={props.row} row={props.row}
col={{ col={{
name: props.column.key, name: props.column.key,
value: props.row[props.column.key], value: get(props.row, props.column.key),
depth: props.row.__depth || 0, depth: props.row.__depth || 0,
}} }}
rows={local.data} rows={local.data}
@ -448,7 +455,7 @@ export const TableList: FC<TableListProp> = ({
row={props.row} row={props.row}
col={{ col={{
name: props.column.key, name: props.column.key,
value: props.row[props.column.key], value: get(props.row, props.column.key),
depth: props.row.__depth || 0, depth: props.row.__depth || 0,
}} }}
rows={local.data} rows={local.data}

View File

@ -25,7 +25,6 @@ export const logout = (url_login?: string) => {
localStorage.removeItem("user" + id_site); localStorage.removeItem("user" + id_site);
} }
if (url_login !== getPathname()) { if (url_login !== getPathname()) {
console.log(url_login, getPathname()); location.href = `${getBasename()}${url_login}`;
// location.href = `${getBasename()}${url_login}`;
} }
}; };