@visns-studio/visns-components 2.4.6 → 2.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,6 +98,7 @@ const DataGrid = ({
98
98
  gridHeight,
99
99
  settings,
100
100
  setFilterData,
101
+ setConfig,
101
102
  style,
102
103
  }) => {
103
104
  const navigate = useNavigate();
@@ -267,6 +268,23 @@ const DataGrid = ({
267
268
  setDataReload(randomNumber);
268
269
  };
269
270
 
271
+ const handleSort = (value) => {
272
+ setConfig((prevState) => {
273
+ const { id, dir } = value || {}; // Destructure id and dir from value (if provided)
274
+ const sortBy = id || null;
275
+ const sort = dir === 1 ? 'asc' : dir === -1 ? 'desc' : null;
276
+
277
+ return {
278
+ ...prevState,
279
+ ajaxSetting: {
280
+ ...prevState.ajaxSetting,
281
+ sortBy,
282
+ sort,
283
+ },
284
+ };
285
+ });
286
+ };
287
+
270
288
  const onRowClick = useCallback(
271
289
  (rowProps, event) => {
272
290
  const cellElement = event.target.closest(
@@ -1401,7 +1419,6 @@ const DataGrid = ({
1401
1419
  columns={gridColumns}
1402
1420
  dataSource={data}
1403
1421
  filterValue={filterValue}
1404
- defaultSortInfo={sortInfo}
1405
1422
  enableColumnAutosize={false}
1406
1423
  enableColumnFilterContextMenu={false}
1407
1424
  enableSelection={false}
@@ -1414,11 +1431,20 @@ const DataGrid = ({
1414
1431
  minRowHeight={40}
1415
1432
  onFilterValueChange={setFilterValue}
1416
1433
  onLimitChange={setLimit}
1434
+ onSortInfoChange={handleSort}
1417
1435
  onRenderRow={onRenderRow}
1418
1436
  pagination
1419
1437
  renderColumnContextMenu={renderColumnContextMenu}
1420
1438
  rowHeight={null}
1421
1439
  showZebraRows={true}
1440
+ sortInfo={
1441
+ ajaxSetting.sortBy && ajaxSetting.sort
1442
+ ? {
1443
+ name: ajaxSetting.sortBy,
1444
+ dir: ajaxSetting.sort === 'asc' ? 1 : -1,
1445
+ }
1446
+ : null
1447
+ }
1422
1448
  style={gridStyle}
1423
1449
  />
1424
1450
  <Popup
@@ -53,6 +53,7 @@ function CmsIndex({ setting, userProfile }) {
53
53
  <DataGrid
54
54
  {...config}
55
55
  gridHeight={windowHeight * 0.65}
56
+ setConfig={setConfig}
56
57
  style={
57
58
  userProfile?.settings?.style ||
58
59
  {}
@@ -1274,7 +1274,12 @@ const DataGrid = forwardRef(
1274
1274
  .map((nf) => value[nf])
1275
1275
  .join(' ');
1276
1276
  } else {
1277
- if (value && value[column.nameFrom]) {
1277
+ if (
1278
+ value &&
1279
+ value.hasOwnProperty(
1280
+ column.nameFrom
1281
+ )
1282
+ ) {
1278
1283
  value = value[column.nameFrom];
1279
1284
  }
1280
1285
  }
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  "react-dom": "^17.0.1"
43
43
  },
44
44
  "name": "@visns-studio/visns-components",
45
- "version": "2.4.6",
45
+ "version": "2.4.8",
46
46
  "description": "Various packages to assist in the development of our Custom Applications.",
47
47
  "main": "index.js",
48
48
  "scripts": {