ms-react-table 1.0.0 → 2.0.1

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.
package/dist/index.js CHANGED
@@ -30,15 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- MsReactTable: () => MsReactTable_default
33
+ default: () => MsReactTable_default
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/MsReactTable.tsx
38
- var import_react5 = __toESM(require("react"));
38
+ var import_react12 = __toESM(require("react"));
39
39
 
40
40
  // src/contextAPI/MsTableProvider.tsx
41
- var import_react3 = require("react");
41
+ var import_react4 = require("react");
42
42
 
43
43
  // src/contextAPI/MsTableContext.tsx
44
44
  var import_react = require("react");
@@ -53,7 +53,7 @@ var useTable = () => {
53
53
  };
54
54
 
55
55
  // src/components/HeaderActionMenu/HeaderActionMenu.tsx
56
- var import_react2 = require("react");
56
+ var import_react3 = require("react");
57
57
 
58
58
  // src/_assets/icons/index.tsx
59
59
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -71,19 +71,47 @@ var prevIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { xmlns: "http
71
71
  var nextIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "32", height: "32", fill: "currentColor", viewBox: "0 0 256 256", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z" }) });
72
72
  var doublePipeArrow = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "32", height: "32", fill: "currentColor", viewBox: "0 0 256 256", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M112,48V208a8,8,0,0,1-16,0V136H43.31l18.35,18.34a8,8,0,0,1-11.32,11.32l-32-32a8,8,0,0,1,0-11.32l32-32a8,8,0,0,1,11.32,11.32L43.31,120H96V48a8,8,0,0,1,16,0Zm125.66,74.34-32-32a8,8,0,0,0-11.32,11.32L212.69,120H160V48a8,8,0,0,0-16,0V208a8,8,0,0,0,16,0V136h52.69l-18.35,18.34a8,8,0,0,0,11.32,11.32l32-32A8,8,0,0,0,237.66,122.34Z" }) });
73
73
  var hideShow = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "32", height: "32", fill: "currentColor", viewBox: "0 0 256 256", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M64,105V40a8,8,0,0,0-16,0v65a32,32,0,0,0,0,62v49a8,8,0,0,0,16,0V167a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,56,152Zm80-95V40a8,8,0,0,0-16,0V57a32,32,0,0,0,0,62v97a8,8,0,0,0,16,0V119a32,32,0,0,0,0-62Zm-8,47a16,16,0,1,1,16-16A16,16,0,0,1,128,104Zm104,64a32.06,32.06,0,0,0-24-31V40a8,8,0,0,0-16,0v97a32,32,0,0,0,0,62v17a8,8,0,0,0,16,0V199A32.06,32.06,0,0,0,232,168Zm-32,16a16,16,0,1,1,16-16A16,16,0,0,1,200,184Z" }) });
74
+ var closeIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 256 256", children: [
75
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { width: "64", height: "64", fill: "none" }),
76
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "200", y1: "56", x2: "56", y2: "200", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" }),
77
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "200", y1: "200", x2: "56", y2: "56", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" })
78
+ ] });
79
+ var rangeIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 256 256", children: [
80
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { width: "256", height: "256", fill: "none" }),
81
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "216", y1: "128", x2: "40", y2: "128", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" }),
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "128", y1: "16", x2: "128", y2: "96", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" }),
83
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "160 64 128 96 96 64", fill: "none", stroke: "currentColor", "stroke-linecap": "round", strokeLinejoin: "round", strokeWidth: "16" }),
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "128", y1: "240", x2: "128", y2: "160", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" }),
85
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "96 192 128 160 160 192", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" })
86
+ ] });
74
87
 
75
- // src/components/HeaderActionMenu/HeaderActionMenu.tsx
88
+ // src/components/FormElements/CheckBox.tsx
89
+ var import_react2 = require("react");
76
90
  var import_jsx_runtime2 = require("react/jsx-runtime");
91
+ var CheckBox = (props) => {
92
+ const { id, name, checked, onChange, disabled } = props;
93
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "ms-checkbox-wrapper", children: [
94
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", className: "ms-promoted-input-checkbox", disabled, checked, onChange: disabled ? () => {
95
+ } : onChange }),
96
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "ms-checkbox-box" }),
97
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("use", { xlinkHref: `#${id}` }) }),
98
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("symbol", { id, viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeMiterlimit: "10", fill: "none", d: "M22.9 3.7l-15.2 16.6-6.6-7.1" }) }) })
99
+ ] }) });
100
+ };
101
+ var CheckBox_default = (0, import_react2.memo)(CheckBox);
102
+
103
+ // src/components/HeaderActionMenu/HeaderActionMenu.tsx
104
+ var import_jsx_runtime3 = require("react/jsx-runtime");
77
105
  var HeaderActionMenu = (props) => {
78
106
  const { state, api: { onColumnPin, onSortColumn, onAutoColumnResize, onColumnReset, updateState } } = useTable();
79
- const [showColumnList, toggleColumnList] = (0, import_react2.useState)(false);
80
- const [columnList, setColumnList] = (0, import_react2.useState)(state.colConfigs);
81
- const [searchkey, setSearchkey] = (0, import_react2.useState)("");
82
- (0, import_react2.useEffect)(() => {
107
+ const [showColumnList, toggleColumnList] = (0, import_react3.useState)(false);
108
+ const [columnList, setColumnList] = (0, import_react3.useState)(state.colConfigs);
109
+ const [searchkey, setSearchkey] = (0, import_react3.useState)("");
110
+ (0, import_react3.useEffect)(() => {
83
111
  setColumnList(state.colConfigs);
84
112
  onSearchHeader(searchkey);
85
113
  }, [state.colConfigs]);
86
- const onCheckboxChange = (dataIndex, e) => {
114
+ const onCheckboxChange = (0, import_react3.useCallback)((dataIndex, e) => {
87
115
  let newConfig = state.colConfigs.map((item) => {
88
116
  return {
89
117
  ...item,
@@ -95,7 +123,7 @@ var HeaderActionMenu = (props) => {
95
123
  colConfigs: newConfig
96
124
  });
97
125
  setColumnList(newConfig);
98
- };
126
+ }, []);
99
127
  const onSearchHeader = (value) => {
100
128
  let newlist = [];
101
129
  if (value) {
@@ -110,31 +138,31 @@ var HeaderActionMenu = (props) => {
110
138
  }
111
139
  setSearchkey(value);
112
140
  };
113
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: props.ref, className: "header-menu", style: props.style, children: showColumnList ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "column-list", children: [
114
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "search", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "text", placeholder: "Search header", className: "search-input", onChange: (e) => onSearchHeader(e.target.value) }) }),
115
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "list", children: columnList.map((item) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "item", children: [
116
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { className: "ms-checkbox-input", type: "checkbox", id: item.dataIndex, checked: !item.isHidden, onChange: (e) => onCheckboxChange(item.dataIndex, e) }),
117
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: item.dataIndex, children: item.title })
141
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: props.ref, className: "header-menu", style: props.style, children: showColumnList ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "column-list", children: [
142
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "search", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "text", placeholder: "Search header", className: "search-input", onChange: (e) => onSearchHeader(e.target.value) }) }),
143
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "list", children: columnList.map((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "item", children: [
144
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CheckBox_default, { id: item.dataIndex, checked: !item.isHidden, onChange: (e) => onCheckboxChange(item.dataIndex, e) }),
145
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: item.dataIndex, children: item.title })
118
146
  ] }, item.dataIndex + "_item")) })
119
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("ul", { children: [
120
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { onClick: () => onSortColumn(props.dataIndex, "asc"), children: [
121
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: angleUpIcon }),
147
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("ul", { children: [
148
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { onClick: () => onSortColumn(props.dataIndex, "asc"), children: [
149
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: angleUpIcon }),
122
150
  `Sort By Ascending`
123
151
  ] }),
124
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { onClick: () => onSortColumn(props.dataIndex, "desc"), children: [
125
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: angleDownIcon }),
152
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { onClick: () => onSortColumn(props.dataIndex, "desc"), children: [
153
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: angleDownIcon }),
126
154
  `Sort By Descending`
127
155
  ] }),
128
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { onClick: () => onAutoColumnResize("all"), children: [
129
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: doublePipeArrow }),
156
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { onClick: () => onAutoColumnResize("all"), children: [
157
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: doublePipeArrow }),
130
158
  `Autosize All Column`
131
159
  ] }),
132
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { onClick: () => toggleColumnList(true), children: [
133
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: hideShow }),
160
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { onClick: () => toggleColumnList(true), children: [
161
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: hideShow }),
134
162
  `Hide/Show Columns`
135
163
  ] }),
136
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { onClick: onColumnReset, children: [
137
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: reloadIcon }),
164
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { onClick: onColumnReset, children: [
165
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: reloadIcon }),
138
166
  `Reset Columns`
139
167
  ] })
140
168
  ] }) });
@@ -142,10 +170,10 @@ var HeaderActionMenu = (props) => {
142
170
  var HeaderActionMenu_default = HeaderActionMenu;
143
171
 
144
172
  // src/components/Overlay.tsx
145
- var import_jsx_runtime3 = require("react/jsx-runtime");
173
+ var import_jsx_runtime4 = require("react/jsx-runtime");
146
174
  var Overlay = (props) => {
147
- const { message = "No Records to show", style } = props;
148
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "overlay-message", style, children: message });
175
+ const { message = "No Records to show", style, customComponentForNoRecords } = props;
176
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "overlay-message", style, children: customComponentForNoRecords ? customComponentForNoRecords : message });
149
177
  };
150
178
  var Overlay_default = Overlay;
151
179
 
@@ -164,61 +192,190 @@ function sortData(data, dataIndex, sortBy) {
164
192
  return sortBy === "asc" ? comparison : -comparison;
165
193
  });
166
194
  }
195
+ function applyOperation(fieldValue, rule) {
196
+ if (rule.type === "string") {
197
+ const val = String(fieldValue).toLowerCase();
198
+ const target = String(rule.value).toLowerCase();
199
+ switch (rule.operation) {
200
+ case "include":
201
+ return val.includes(target);
202
+ case "not include":
203
+ return !val.includes(target);
204
+ case "=":
205
+ return val === target;
206
+ case "!=":
207
+ return val !== target;
208
+ default:
209
+ return true;
210
+ }
211
+ }
212
+ if (rule.type === "number") {
213
+ const val = Number(fieldValue);
214
+ const target = Number(rule.value);
215
+ switch (rule.operation) {
216
+ case "=":
217
+ return val === target;
218
+ case "!=":
219
+ return val !== target;
220
+ case ">":
221
+ return val > target;
222
+ case "<":
223
+ return val < target;
224
+ default:
225
+ return true;
226
+ }
227
+ }
228
+ if (rule.type === "date") {
229
+ let [fromDate, toDate] = rule.value;
230
+ const val = new Date(fieldValue)?.getTime();
231
+ const target_1 = new Date(fromDate)?.getTime();
232
+ const target_2 = new Date(toDate)?.getTime();
233
+ switch (rule.operation) {
234
+ case "=":
235
+ return val === target_1;
236
+ case "!=":
237
+ return val !== target_1;
238
+ case ">":
239
+ return val >= target_1;
240
+ case "<":
241
+ return val < target_1;
242
+ case "<>":
243
+ return val > target_1 && val < target_2;
244
+ default:
245
+ return true;
246
+ }
247
+ }
248
+ if (rule.type === "boolean") {
249
+ const val = Boolean(fieldValue);
250
+ const target = rule.value == "true" ? true : false;
251
+ return val === target;
252
+ }
253
+ return true;
254
+ }
255
+ function exportToCSV(data, fileName) {
256
+ const headers = Object.keys(data[0]).join(",");
257
+ const rows = data.map((obj) => Object.values(obj).join(",")).join("\n");
258
+ const csvContent = headers + "\n" + rows;
259
+ const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
260
+ const link = document.createElement("a");
261
+ link.href = URL.createObjectURL(blob);
262
+ link.download = fileName + ".csv";
263
+ link.click();
264
+ }
265
+ function exportToExcel(data, fileName) {
266
+ const headers = Object.keys(data[0]);
267
+ const rows = data.map((obj) => Object.values(obj));
268
+ let html = "<table border='1'><tr>";
269
+ headers.forEach((h) => html += `<th>${h}</th>`);
270
+ html += "</tr>";
271
+ rows.forEach((row) => {
272
+ html += "<tr>";
273
+ row.forEach((val) => html += `<td>${val}</td>`);
274
+ html += "</tr>";
275
+ });
276
+ html += "</table>";
277
+ const blob = new Blob([html], { type: "application/vnd.ms-excel" });
278
+ const link = document.createElement("a");
279
+ link.href = URL.createObjectURL(blob);
280
+ link.download = fileName + ".xls";
281
+ link.click();
282
+ }
167
283
 
168
284
  // src/contextAPI/MsTableProvider.tsx
169
- var import_jsx_runtime4 = require("react/jsx-runtime");
170
- var TableProvider = (props) => {
171
- const actionMenuRef = (0, import_react3.useRef)(null);
285
+ var import_jsx_runtime5 = require("react/jsx-runtime");
286
+ var TableProvider = (0, import_react4.forwardRef)((props, ref) => {
287
+ const actionMenuRef = (0, import_react4.useRef)(null);
172
288
  const {
173
289
  columns,
174
- data,
290
+ data = [],
175
291
  children,
176
292
  pageSizeOptions = [],
177
293
  isClientSideRendering = true,
178
- totalRecords,
179
- tbodyRef,
180
- theadRef,
181
- onRowClick
294
+ hideDefaultFilterButton = false,
295
+ onRowSelect,
296
+ toggleModalFilter,
297
+ customComponentForNoRecords,
298
+ customComponentForFooter,
299
+ setRowData,
300
+ rowSelectConfig,
301
+ showPagination = true
182
302
  } = props;
183
- const tbodyHeight = tbodyRef?.current?.clientHeight;
184
- const theadHeight = theadRef?.current?.clientHeight;
185
- const [showActionMenu, setActionMenu] = (0, import_react3.useState)(false);
186
- const [selectedHeaderCell, setHeaderCell] = (0, import_react3.useState)("");
187
- const [menuPosition, setMenuPosition] = (0, import_react3.useState)({
303
+ const [showActionMenu, setActionMenu] = (0, import_react4.useState)(false);
304
+ const [selectedHeaderCell, setHeaderCell] = (0, import_react4.useState)("");
305
+ const [ssrList, setSSRList] = (0, import_react4.useState)([]);
306
+ const [totalSSRCount, setTotalSSRCount] = (0, import_react4.useState)(0);
307
+ const [menuPosition, setMenuPosition] = (0, import_react4.useState)({
188
308
  top: 0,
189
309
  right: 0,
190
310
  left: 0
191
311
  });
192
- const [state, setState] = (0, import_react3.useState)({
193
- prevColConfig: columns,
194
- colConfigs: columns,
312
+ const getColumnConfig = (0, import_react4.useMemo)(() => {
313
+ let list = columns.map((item) => {
314
+ let { title, dataIndex, isHidden = false, width = 80, type = "string", align = "left", sortable = true, resizable = true, pinned = "", isFilterEnabled = false, hideActionMenu = false, cellRenderer, sortKey = "", displayAs } = item;
315
+ return {
316
+ title,
317
+ dataIndex,
318
+ isHidden,
319
+ width,
320
+ type,
321
+ align,
322
+ sortable,
323
+ sortKey,
324
+ resizable,
325
+ pinned,
326
+ isFilterEnabled,
327
+ hideActionMenu,
328
+ displayAs,
329
+ cellRenderer
330
+ };
331
+ });
332
+ return list;
333
+ }, [columns]);
334
+ const [state, setState] = (0, import_react4.useState)({
335
+ prevColConfig: getColumnConfig,
336
+ colConfigs: getColumnConfig,
195
337
  rowData: [],
196
338
  allRowData: data,
197
339
  currentPage: 1,
198
340
  pageSize: pageSizeOptions.length > 0 ? pageSizeOptions[0] : 50,
199
341
  totalRecords: isClientSideRendering ? data.length : props?.totalRecords || 0,
200
342
  selectedRows: [],
201
- pageSizeOptions: pageSizeOptions.length > 0 ? pageSizeOptions : [50, 100, 200, 500],
202
- isAutoSizeAllColumns: false
343
+ selectedIndex: [],
344
+ pageSizeOptions: pageSizeOptions.length > 0 ? pageSizeOptions : [20, 50, 100],
345
+ isAutoSizeAllColumns: false,
346
+ filters: {},
347
+ customComponentForFooter,
348
+ hideDefaultFilterButton: hideDefaultFilterButton || false,
349
+ isClientSideRendering,
350
+ rowSelectConfig
203
351
  });
204
- (0, import_react3.useEffect)(() => {
352
+ const [refreshPage, setRefreshPage] = (0, import_react4.useState)(false);
353
+ (0, import_react4.useEffect)(() => {
354
+ if (refreshPage) {
355
+ getListFromServer();
356
+ }
357
+ }, [refreshPage]);
358
+ (0, import_react4.useEffect)(() => {
205
359
  if (isClientSideRendering) {
206
360
  const { currentPage, pageSize } = state;
207
361
  let list = data.slice(currentPage - 1, pageSize * currentPage - 1);
208
362
  setState((prevState) => ({
209
363
  ...prevState,
210
- rowData: list
364
+ rowData: showPagination ? list : data
211
365
  }));
366
+ } else {
367
+ getListFromServer();
212
368
  }
213
369
  }, []);
214
- const onRowSelect = (0, import_react3.useCallback)((rowData) => {
370
+ const onRowSelectionChange = (0, import_react4.useCallback)((rowData, selectedIndex) => {
215
371
  setState((prevState) => ({
216
372
  ...prevState,
217
- selectedRows: [...prevState.selectedRows, rowData]
373
+ selectedRows: rowData,
374
+ selectedIndex
218
375
  }));
219
- onRowClick ? onRowClick(rowData) : null;
376
+ onRowSelect ? onRowSelect(rowData) : null;
220
377
  }, []);
221
- const onColumnResize = (0, import_react3.useCallback)((dataIndex, newWidth) => {
378
+ const onColumnResize = (0, import_react4.useCallback)((dataIndex, newWidth) => {
222
379
  setState((prevState) => ({
223
380
  ...prevState,
224
381
  colConfigs: prevState.colConfigs.map(
@@ -228,36 +385,50 @@ var TableProvider = (props) => {
228
385
  }));
229
386
  }, []);
230
387
  const onPageChange = (direction) => {
231
- const { pageSize, totalRecords: totalRecords2, allRowData, currentPage } = state;
388
+ const { pageSize, totalRecords, allRowData, currentPage } = state;
232
389
  var goToPageNo = 0;
233
390
  if (direction == "first") {
234
391
  goToPageNo = 1;
235
392
  } else if (direction == "last") {
236
- goToPageNo = Math.ceil(totalRecords2 / pageSize);
393
+ goToPageNo = Math.ceil(totalRecords / pageSize);
237
394
  } else if (direction == "next") {
238
395
  goToPageNo = currentPage + 1;
239
396
  } else if (direction == "prev") {
240
397
  goToPageNo = currentPage - 1;
241
398
  }
242
- let list = data.slice(goToPageNo - 1, pageSize * goToPageNo - 1);
243
399
  setState((prevState) => ({
244
400
  ...prevState,
245
- currentPage: goToPageNo,
246
- rowData: list
401
+ currentPage: goToPageNo
247
402
  }));
403
+ if (!isClientSideRendering) {
404
+ setRefreshPage(true);
405
+ }
248
406
  };
249
407
  const onPageSizeChange = (pageSize) => {
408
+ if (!isClientSideRendering) {
409
+ setState((prevState) => ({
410
+ ...prevState,
411
+ selectedIndex: [],
412
+ selectedRows: [],
413
+ currentPage: 1,
414
+ pageSize
415
+ }));
416
+ setRefreshPage(true);
417
+ return;
418
+ }
250
419
  const { allRowData } = state;
251
420
  let list = allRowData.slice(0, pageSize - 1);
252
421
  setState((prevState) => ({
253
422
  ...prevState,
423
+ selectedIndex: [],
424
+ selectedRows: [],
254
425
  currentPage: 1,
255
426
  pageSize,
256
427
  rowData: list
257
428
  }));
258
429
  };
259
- const toggleActionMenu = (dataIndex, showMenu, ref) => {
260
- const position = ref.current.getBoundingClientRect();
430
+ const toggleActionMenu = (dataIndex, showMenu, ref2) => {
431
+ const position = ref2.current.getBoundingClientRect();
261
432
  let left = position.x + position.width;
262
433
  setMenuPosition({
263
434
  top: position.height,
@@ -277,19 +448,22 @@ var TableProvider = (props) => {
277
448
  if (sortBy == "") {
278
449
  setState((prevState) => ({
279
450
  ...prevState,
280
- colConfigs: columns2,
281
- rowData: data
451
+ colConfigs: columns2
282
452
  }));
453
+ if (!isClientSideRendering) {
454
+ setRefreshPage(true);
455
+ }
283
456
  return;
284
457
  }
285
- let sortedList = sortData(data, dataIndex, sortBy);
286
458
  setState((prevState) => ({
287
459
  ...prevState,
288
- colConfigs: columns2,
289
- rowData: sortedList
460
+ colConfigs: columns2
290
461
  }));
291
462
  setActionMenu(false);
292
463
  setHeaderCell("");
464
+ if (!isClientSideRendering) {
465
+ setRefreshPage(true);
466
+ }
293
467
  };
294
468
  const onColumnPin = (pinDirection) => {
295
469
  const { colConfigs } = state;
@@ -324,20 +498,35 @@ var TableProvider = (props) => {
324
498
  pageSize: pageSizeOptions.length > 0 ? pageSizeOptions[0] : 50,
325
499
  totalRecords: isClientSideRendering ? data.length : props?.totalRecords || 0,
326
500
  selectedRows: [],
327
- pageSizeOptions: pageSizeOptions.length > 0 ? pageSizeOptions : [50, 100, 200, 500],
328
- isAutoSizeAllColumns: false
501
+ selectedIndex: [],
502
+ pageSizeOptions: pageSizeOptions.length > 0 ? pageSizeOptions : [20, 50, 100],
503
+ isAutoSizeAllColumns: false,
504
+ hideDefaultFilterButton,
505
+ filters: {}
329
506
  });
330
507
  setActionMenu(false);
331
508
  };
332
- const updateState = (0, import_react3.useCallback)((newState) => {
509
+ const onFilterApply = (filters) => {
510
+ setState((prev) => ({
511
+ ...prev,
512
+ filters
513
+ }));
514
+ toggleModalFilter(false);
515
+ if (!isClientSideRendering) {
516
+ setRefreshPage(true);
517
+ }
518
+ };
519
+ const onFilterReset = () => {
520
+ };
521
+ const updateState = (0, import_react4.useCallback)((newState) => {
333
522
  setState((prev) => ({
334
523
  ...prev,
335
524
  ...newState
336
525
  }));
337
526
  }, []);
338
- const api = (0, import_react3.useMemo)(
527
+ const api = (0, import_react4.useMemo)(
339
528
  () => ({
340
- onRowSelect,
529
+ onRowSelectionChange,
341
530
  onColumnResize,
342
531
  onAutoColumnResize,
343
532
  onPageChange,
@@ -346,15 +535,15 @@ var TableProvider = (props) => {
346
535
  onColumnPin,
347
536
  onSortColumn,
348
537
  updateState,
349
- onColumnReset
538
+ onColumnReset,
539
+ onFilterApply,
540
+ onFilterReset,
541
+ toggleModalFilter
350
542
  }),
351
- [onRowSelect, onColumnResize, onAutoColumnResize, onPageChange, onPageSizeChange, toggleActionMenu, onColumnPin, onSortColumn, updateState, onColumnReset]
352
- );
353
- const contextValue = (0, import_react3.useMemo)(
354
- () => ({ state, api }),
355
- [state, api]
543
+ [onRowSelectionChange, onColumnResize, onAutoColumnResize, onPageChange, onPageSizeChange, toggleActionMenu, onColumnPin, onSortColumn, updateState, onColumnReset]
356
544
  );
357
- (0, import_react3.useEffect)(() => {
545
+ const contextValue = { state, api, ssrList, totalSSRCount };
546
+ (0, import_react4.useEffect)(() => {
358
547
  function handleClickOutside(event) {
359
548
  if (actionMenuRef && "current" in actionMenuRef && actionMenuRef.current && !actionMenuRef.current.contains(event.target)) {
360
549
  setActionMenu(false);
@@ -363,25 +552,101 @@ var TableProvider = (props) => {
363
552
  document.addEventListener("mousedown", handleClickOutside);
364
553
  return () => document.removeEventListener("mousedown", handleClickOutside);
365
554
  }, [actionMenuRef, setActionMenu]);
366
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MsTableContext_default.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `table-wrapper ${state.isAutoSizeAllColumns ? "ms-auto-width" : ""}`, children: [
555
+ const reformData = () => {
556
+ let list = data;
557
+ const { filters, colConfigs, pageSize, currentPage } = state;
558
+ if (Object.keys(filters).length > 0) {
559
+ list = data.filter(
560
+ (row) => Object.entries(filters).every(
561
+ ([key, rule]) => applyOperation(row[key], rule)
562
+ )
563
+ );
564
+ }
565
+ let sortedCol = colConfigs.filter((item) => item.sortKey != "");
566
+ if (sortedCol.length > 0) {
567
+ list = sortData(list, sortedCol[0].dataIndex, sortedCol[0].sortKey || "");
568
+ }
569
+ let x = showPagination ? list.slice((currentPage - 1) * pageSize, pageSize * currentPage) : list;
570
+ setState((prev) => ({
571
+ ...prev,
572
+ rowData: x,
573
+ totalRecords: list.length
574
+ }));
575
+ };
576
+ const getListFromServer = () => {
577
+ const { filters, colConfigs, pageSize, currentPage } = state;
578
+ let sortedCol = colConfigs.filter((item) => item.sortKey != "");
579
+ let sortBy = {};
580
+ if (sortedCol.length > 0) {
581
+ sortBy.key = sortedCol[0]?.dataIndex;
582
+ sortBy.sortBy = sortedCol[0]?.sortKey;
583
+ }
584
+ if (typeof setRowData === "function") {
585
+ setRowData(currentPage, pageSize, filters, sortBy);
586
+ setRefreshPage(false);
587
+ }
588
+ };
589
+ (0, import_react4.useEffect)(() => {
590
+ if (isClientSideRendering) {
591
+ reformData();
592
+ }
593
+ }, [state.pageSize, state.colConfigs, state.filters, state.currentPage]);
594
+ (0, import_react4.useImperativeHandle)(ref, () => ({
595
+ showFilterModal(status) {
596
+ toggleModalFilter(status);
597
+ },
598
+ setRowData(list, totalCount) {
599
+ const { rowSelectConfig: rowSelectConfig2 } = state;
600
+ let defaultCheckedIndex = [];
601
+ let defaultSelectedRows = [];
602
+ if (rowSelectConfig2 && rowSelectConfig2?.isChecked) {
603
+ list.map((row, index) => {
604
+ if (rowSelectConfig2?.isChecked?.(row)) {
605
+ defaultSelectedRows.push(row);
606
+ defaultCheckedIndex.push(index);
607
+ }
608
+ });
609
+ }
610
+ setState((prev) => ({
611
+ ...prev,
612
+ selectedIndex: defaultCheckedIndex,
613
+ selectedRows: defaultSelectedRows,
614
+ rowData: list,
615
+ totalRecords: totalCount
616
+ }));
617
+ },
618
+ exportToCSV(fileName) {
619
+ exportToCSV(state.rowData, fileName);
620
+ },
621
+ exportToExcel(fileName) {
622
+ exportToExcel(state.rowData, fileName);
623
+ },
624
+ getSelectedRows() {
625
+ return state.selectedRows;
626
+ }
627
+ }), [refreshPage]);
628
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MsTableContext_default.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `ms-table-wrapper ${props.className} ${state.isAutoSizeAllColumns ? "ms-auto-width" : ""}`, children: [
367
629
  children,
368
- state.rowData.length == 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Overlay_default, { style: { height: tbodyHeight, top: theadHeight } }),
369
- showActionMenu && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HeaderActionMenu_default, { ref: actionMenuRef, dataIndex: selectedHeaderCell, style: { top: menuPosition.top, left: menuPosition.left } })
630
+ state.rowData.length == 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Overlay_default, { customComponentForNoRecords }),
631
+ showActionMenu && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HeaderActionMenu_default, { ref: actionMenuRef, dataIndex: selectedHeaderCell, style: { top: menuPosition.top, left: menuPosition.left } })
370
632
  ] }) });
371
- };
633
+ });
634
+
635
+ // src/components/Header/msTableHeader.tsx
636
+ var import_react6 = require("react");
372
637
 
373
638
  // src/components/Header/HeaderCell.tsx
374
- var import_react4 = require("react");
375
- var import_jsx_runtime5 = require("react/jsx-runtime");
639
+ var import_react5 = require("react");
640
+ var import_jsx_runtime6 = require("react/jsx-runtime");
376
641
  var HeaderCell = (props) => {
377
- const thRef = (0, import_react4.useRef)(null);
642
+ const thRef = (0, import_react5.useRef)(null);
378
643
  const { title, cellRenderer, hideActionMenu, dataIndex, width: defaultWidth, resizable = true, pinned } = props;
379
644
  const minWidth = title === "" ? 30 : 50;
380
- const [width, setWidth] = (0, import_react4.useState)(defaultWidth || 80);
381
- const startX = (0, import_react4.useRef)(0);
382
- const startWidth = (0, import_react4.useRef)(0);
645
+ const [width, setWidth] = (0, import_react5.useState)(defaultWidth || 80);
646
+ const startX = (0, import_react5.useRef)(0);
647
+ const startWidth = (0, import_react5.useRef)(0);
383
648
  const { state: { isAutoSizeAllColumns, ...rest }, api } = useTable();
384
- (0, import_react4.useEffect)(() => {
649
+ (0, import_react5.useEffect)(() => {
385
650
  if (isAutoSizeAllColumns) {
386
651
  let element = thRef.current.getBoundingClientRect();
387
652
  if (api.onColumnResize) {
@@ -392,7 +657,6 @@ var HeaderCell = (props) => {
392
657
  const onMouseDown = (e) => {
393
658
  startX.current = e.clientX;
394
659
  startWidth.current = thRef.current?.offsetWidth || width;
395
- console.log("Start Width:", startWidth.current);
396
660
  document.addEventListener("mousemove", onMouseMove);
397
661
  document.addEventListener("mouseup", onMouseUp);
398
662
  };
@@ -411,107 +675,563 @@ var HeaderCell = (props) => {
411
675
  document.removeEventListener("mousemove", onMouseMove);
412
676
  document.removeEventListener("mouseup", onMouseUp);
413
677
  };
414
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
678
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
415
679
  "th",
416
680
  {
417
681
  className: `${props.headerCellClassName} ${pinned ? pinned + "-pinned" : ""}`,
418
682
  ref: thRef,
419
- style: { width: width || 80 },
420
- children: [
421
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "ms-table-header-cell ", children: [
422
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "ms-table-header-cell-title", onClick: () => api.onSortColumn(dataIndex, !props.sortKey ? "asc" : props.sortKey == "asc" ? "desc" : ""), children: [
683
+ style: { width },
684
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "header-cell-wrapper", children: [
685
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "ms-table-header-cell ", children: [
686
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "ms-table-header-cell-title", onClick: () => api.onSortColumn(dataIndex, !props.sortKey ? "asc" : props.sortKey == "asc" ? "desc" : ""), children: [
423
687
  title,
688
+ " ",
689
+ rest.filters[dataIndex] ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("sup", { children: "*" }) : "",
424
690
  props.sortKey == "asc" ? angleUpIcon : props.sortKey == "desc" ? angleDownIcon : null
425
691
  ] }),
426
- !hideActionMenu && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "ms-table-header-action", title: "View Menu", onClick: () => api.toggleActionMenu(dataIndex, true, thRef), children: verticleThreeDotsIcon })
692
+ !hideActionMenu && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "ms-table-header-action", title: "View Menu", onClick: () => api.toggleActionMenu(dataIndex, true, thRef), children: verticleThreeDotsIcon })
427
693
  ] }),
428
- resizable && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "ms-table-column-resizer", onMouseDown })
429
- ]
694
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: `ms-table-column-resizer ${resizable ? "" : "disabled"}`, onMouseDown: resizable ? onMouseDown : void 0 })
695
+ ] })
430
696
  },
431
697
  dataIndex
432
698
  );
433
699
  };
434
- var HeaderCell_default = HeaderCell;
700
+ var HeaderCell_default = (0, import_react5.memo)(HeaderCell);
435
701
 
436
702
  // src/components/Header/msTableHeader.tsx
437
- var import_jsx_runtime6 = require("react/jsx-runtime");
703
+ var import_jsx_runtime7 = require("react/jsx-runtime");
438
704
  var msTableHeader = (props) => {
439
- const { state, api } = useTable();
440
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
441
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("colgroup", { children: state.colConfigs.map((col) => !col.isHidden && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { width: col.width || 80 }, col.dataIndex)) }),
442
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("thead", { ref: props.ref, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tr", { children: state.colConfigs.map((col) => {
443
- if (!col.isHidden) {
444
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HeaderCell_default, { ...col }, col.dataIndex);
445
- }
446
- }) }) })
705
+ const { state: { rowSelectConfig, rowData, colConfigs, selectedIndex, ...rest }, api } = useTable();
706
+ const [isAllChecked, setIsAllChecked] = (0, import_react6.useState)(false);
707
+ (0, import_react6.useEffect)(() => {
708
+ if (selectedIndex.length > 0) {
709
+ setIsAllChecked(rowData.length == selectedIndex.length);
710
+ } else {
711
+ setIsAllChecked(false);
712
+ }
713
+ }, [selectedIndex]);
714
+ const handleAllSelection = (isChecked) => {
715
+ let nextIndex = [];
716
+ let rows = [];
717
+ if (isChecked) {
718
+ rowData.map((item, key) => {
719
+ let isDisabled = rowSelectConfig?.isDisabled?.(item) || false;
720
+ let isDefaultChecked = rowSelectConfig?.isChecked?.(item) || false;
721
+ if (isDisabled && isDefaultChecked) {
722
+ nextIndex.push(key);
723
+ rows.push(item);
724
+ } else if (!isDisabled) {
725
+ nextIndex.push(key);
726
+ rows.push(item);
727
+ }
728
+ });
729
+ } else {
730
+ rowData.map((item, key) => {
731
+ let isDisabled = rowSelectConfig?.isDisabled?.(item) || false;
732
+ let isDefaultChecked = rowSelectConfig?.isChecked?.(item) || false;
733
+ if (isDisabled && isDefaultChecked) {
734
+ nextIndex.push(key);
735
+ rows.push(item);
736
+ }
737
+ });
738
+ }
739
+ api.onRowSelectionChange(rows, nextIndex);
740
+ setIsAllChecked(isChecked);
741
+ };
742
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
743
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("colgroup", { children: [
744
+ rowSelectConfig && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("col", { width: 50 }, "all_checkbox"),
745
+ colConfigs.map((col) => !col.isHidden && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("col", { width: col.width }, col.dataIndex))
746
+ ] }),
747
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { ref: props.ref, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("tr", { children: [
748
+ rowSelectConfig && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "header-cell-wrapper ", children: [
749
+ rowSelectConfig.selectionMode == "multiple" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CheckBox_default, { id: "all", checked: isAllChecked, onChange: (e) => handleAllSelection(e.target.checked) }) }),
750
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `ms-table-column-resizer ${rowSelectConfig?.isResizable ? "" : "disabled"}` })
751
+ ] }) }, "all_checkbox"),
752
+ colConfigs.map((col) => {
753
+ if (!col.isHidden) {
754
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCell_default, { ...col }, col.dataIndex);
755
+ }
756
+ })
757
+ ] }) })
447
758
  ] });
448
759
  };
449
760
  var msTableHeader_default = msTableHeader;
450
761
 
451
762
  // src/components/Body/DataRowCell.tsx
452
- var import_jsx_runtime7 = require("react/jsx-runtime");
453
- var DataRowCell = ({ dataIndex, value, cellRenderer, width, pinned }) => {
454
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { style: dataIndex !== "name" ? { width: width || "80" } : { width: "80" }, className: `${pinned ? pinned + "-pinned" : ""}`, children: cellRenderer ? cellRenderer(value) : value });
763
+ var import_jsx_runtime8 = require("react/jsx-runtime");
764
+ var DataRowCell = ({ rowData, dataIndex, value, cellRenderer, width, pinned, ...rest }) => {
765
+ const renderData = () => {
766
+ switch (rest.type) {
767
+ case "string":
768
+ return value;
769
+ case "boolean":
770
+ return rest?.displayAs ? value ? rest.displayAs.true : rest.displayAs.false : JSON.stringify(value);
771
+ case "object":
772
+ return JSON.stringify(value);
773
+ default:
774
+ return value;
775
+ }
776
+ };
777
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { style: { width }, className: `${pinned ? pinned + "-pinned" : ""}`, children: cellRenderer ? cellRenderer(rowData, dataIndex) : renderData() });
455
778
  };
456
779
  var DataRowCell_default = DataRowCell;
457
780
 
458
781
  // src/components/Body/msTableBody.tsx
459
- var import_jsx_runtime8 = require("react/jsx-runtime");
782
+ var import_jsx_runtime9 = require("react/jsx-runtime");
460
783
  var msTableBody = (props) => {
461
- const { state, api } = useTable();
462
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tbody", { ref: props.ref, children: state.rowData?.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { onClick: () => api.onRowSelect(row), children: state.colConfigs?.map((col, colIndex) => !col.isHidden && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DataRowCell_default, { dataIndex: col.dataIndex, value: row[col.dataIndex], width: col.width, cellRenderer: col.cellRenderer, pinned: col.pinned })) }, rowIndex)) });
784
+ const { state: { rowData, rowSelectConfig, colConfigs, selectedIndex, ...rest }, api } = useTable();
785
+ const onCheckboxSelectionChange = (currentSelectedRow, index, isChecked) => {
786
+ let prevIndexes = [...selectedIndex];
787
+ let rows = [];
788
+ if (rowSelectConfig?.selectionMode == "multiple") {
789
+ if (isChecked) {
790
+ prevIndexes = [...prevIndexes, index];
791
+ rows = [...rest.selectedRows, currentSelectedRow];
792
+ } else {
793
+ prevIndexes = selectedIndex.filter((key) => index != key);
794
+ rows = rowData.filter((row, key) => prevIndexes.includes(key));
795
+ }
796
+ } else {
797
+ if (isChecked) {
798
+ prevIndexes = [index];
799
+ rows = [currentSelectedRow];
800
+ } else {
801
+ prevIndexes = [];
802
+ }
803
+ }
804
+ api.onRowSelectionChange(rows, prevIndexes);
805
+ };
806
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("tbody", { ref: props.ref, children: rowData?.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("tr", { children: [
807
+ rowSelectConfig && rowSelectConfig.selectionMode && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { style: { width: "50px" }, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-center d-flex", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CheckBox_default, { id: `checkbox_${rowIndex}`, checked: selectedIndex.includes(rowIndex), onChange: (e) => onCheckboxSelectionChange(row, rowIndex, e.target.checked), disabled: rowSelectConfig.isDisabled?.(row) }) }) }),
808
+ colConfigs?.map((col, colIndex) => !col.isHidden && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DataRowCell_default, { type: col.type, dataIndex: col.dataIndex, rowData: row, value: row[col.dataIndex], width: col.width, cellRenderer: col.cellRenderer, pinned: col.pinned, displayAs: col.displayAs }, colIndex + "_col_" + rowIndex))
809
+ ] }, rowIndex + "_row")) });
463
810
  };
464
811
  var msTableBody_default = msTableBody;
465
812
 
813
+ // src/components/FormElements/Button.tsx
814
+ var import_jsx_runtime10 = require("react/jsx-runtime");
815
+ var Button = (props) => {
816
+ const { className, label, ...rest } = props;
817
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: `ms-table-btn ${className}`, ...rest, children: label });
818
+ };
819
+ var Button_default = Button;
820
+
466
821
  // src/components/Footer/msTableFooter.tsx
467
- var import_jsx_runtime9 = require("react/jsx-runtime");
468
- var MsTableFooter = () => {
822
+ var import_jsx_runtime11 = require("react/jsx-runtime");
823
+ var MsTableFooter = (props) => {
469
824
  const { state, api } = useTable();
470
- const { pageSizeOptions, currentPage, pageSize, totalRecords } = state;
825
+ const { pageSizeOptions, currentPage, pageSize, totalRecords, filters, hideDefaultFilterButton, customComponentForFooter } = state;
826
+ let filterCount = Object.keys(filters).length;
471
827
  const lastPageNo = Math.ceil(totalRecords / pageSize);
472
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "table-footer", children: [
473
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "extra-actions" }),
474
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "pagination-controls", children: [
475
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "pagination-info", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "page-size", children: [
476
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("label", { children: "Rows Per Page:" }),
477
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("select", { onChange: (e) => api.onPageSizeChange(parseInt(e.target.value)), value: pageSize, children: state.pageSizeOptions.map((size) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: size, children: size }, size)) })
828
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "table-footer", children: [
829
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "extra-actions", children: [
830
+ hideDefaultFilterButton == false && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button_default, { label: `Filters ${filterCount > 0 ? `(${filterCount})` : ""}`, className: "", onClick: () => props.toggleFilterModal(true) }),
831
+ customComponentForFooter
832
+ ] }),
833
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "pagination-controls", children: [
834
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "pagination-info", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "page-size", children: [
835
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("label", { children: "Rows Per Page:" }),
836
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("select", { onChange: (e) => api.onPageSizeChange(parseInt(e.target.value)), value: pageSize, children: state.pageSizeOptions.map((size) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("option", { value: size, children: size }, size)) })
478
837
  ] }) }),
479
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "record-info", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("label", { children: `${(currentPage - 1) * pageSize + 1} to ${Math.min(currentPage * pageSize, totalRecords)} of ${totalRecords}` }) }),
480
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "pagination-buttons", children: [
481
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Go to First Page", onClick: () => api.onPageChange("first"), children: angleLeftIcon }),
482
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Previous Page", onClick: () => api.onPageChange("prev"), children: prevIcon }),
483
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "current-page", children: [
838
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "record-info", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("label", { children: `${(currentPage - 1) * pageSize + 1} to ${Math.min(currentPage * pageSize, totalRecords)} of ${totalRecords}` }) }),
839
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "pagination-buttons", children: [
840
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Go to First Page", onClick: () => api.onPageChange("first"), children: angleLeftIcon }),
841
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Previous Page", onClick: () => api.onPageChange("prev"), children: prevIcon }),
842
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "current-page", children: [
484
843
  currentPage,
485
844
  " of ",
486
845
  Math.ceil(totalRecords / pageSize)
487
846
  ] }),
488
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Next Page", onClick: () => api.onPageChange("next"), children: nextIcon }),
489
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Go to Last Page", onClick: () => api.onPageChange("last"), children: angleRightIcon })
847
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Next Page", onClick: () => api.onPageChange("next"), children: nextIcon }),
848
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Go to Last Page", onClick: () => api.onPageChange("last"), children: angleRightIcon })
490
849
  ] })
491
850
  ] })
492
851
  ] });
493
852
  };
494
853
  var msTableFooter_default = MsTableFooter;
495
854
 
855
+ // src/components/Filter/FilterModal.tsx
856
+ var import_react11 = require("react");
857
+
858
+ // src/components/Filter/String/TextFilter.tsx
859
+ var import_react7 = require("react");
860
+
861
+ // src/components/FormElements/Input.tsx
862
+ var import_jsx_runtime12 = require("react/jsx-runtime");
863
+ var Input = (props) => {
864
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("input", { ...props }) });
865
+ };
866
+ var Input_default = Input;
867
+
868
+ // src/components/FormElements/Select.tsx
869
+ var import_jsx_runtime13 = require("react/jsx-runtime");
870
+ var Select = (props) => {
871
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("select", { onChange: props.onChange, value: props.value, children: props.option.map((item) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("option", { value: item.value, children: item.label }, props.name + "_" + item.value)) }) });
872
+ };
873
+ var Select_default = Select;
874
+
875
+ // src/components/Filter/String/TextFilter.tsx
876
+ var import_jsx_runtime14 = require("react/jsx-runtime");
877
+ var TextFilter = (colConfig) => {
878
+ const { title, dataIndex, onChange, filterOps, type } = colConfig;
879
+ const [selectedOps, setSelectedOps] = (0, import_react7.useState)("include");
880
+ const [value, setValue] = (0, import_react7.useState)("");
881
+ const options = [
882
+ {
883
+ label: "Contains",
884
+ value: "include"
885
+ },
886
+ {
887
+ label: "Equal to",
888
+ value: "="
889
+ },
890
+ {
891
+ label: "Not Equal to",
892
+ value: "!="
893
+ },
894
+ {
895
+ label: "Does not contain",
896
+ value: "not include"
897
+ }
898
+ ];
899
+ (0, import_react7.useEffect)(() => {
900
+ if (filterOps === void 0) {
901
+ setSelectedOps("include");
902
+ setValue("");
903
+ } else {
904
+ setSelectedOps(filterOps.operation);
905
+ setValue(filterOps.value);
906
+ }
907
+ }, [filterOps]);
908
+ (0, import_react7.useEffect)(() => {
909
+ onChange(dataIndex, { type, operation: selectedOps, value });
910
+ }, [selectedOps, value]);
911
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "ms-form-item", children: [
912
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("label", { children: title }),
913
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "", children: [
914
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Select_default, { option: options, onChange: (e) => setSelectedOps(e.target.value), value: selectedOps }),
915
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Input_default, { name: dataIndex, onChange: (e) => setValue(e.target.value), value })
916
+ ] })
917
+ ] });
918
+ };
919
+ var TextFilter_default = (0, import_react7.memo)(TextFilter);
920
+
921
+ // src/components/Filter/Number/NumberFilter.tsx
922
+ var import_react8 = require("react");
923
+ var import_jsx_runtime15 = require("react/jsx-runtime");
924
+ var NumberFilter = (colConfig) => {
925
+ const { title, dataIndex, onChange, filterOps } = colConfig;
926
+ const [selectedOps, setSelectedOps] = (0, import_react8.useState)(filterOps?.operation || "=");
927
+ const [value, setValue] = (0, import_react8.useState)(filterOps?.value || "");
928
+ const options = [
929
+ {
930
+ label: "Equal to",
931
+ value: "="
932
+ },
933
+ {
934
+ label: "Not Equal to",
935
+ value: "!="
936
+ },
937
+ {
938
+ label: "Greater than",
939
+ value: ">"
940
+ },
941
+ {
942
+ label: "Less than",
943
+ value: "<"
944
+ }
945
+ ];
946
+ (0, import_react8.useEffect)(() => {
947
+ if (filterOps === void 0) {
948
+ setSelectedOps("=");
949
+ setValue("");
950
+ } else {
951
+ setSelectedOps(filterOps.operation);
952
+ setValue(filterOps.value);
953
+ }
954
+ }, []);
955
+ (0, import_react8.useEffect)(() => {
956
+ onChange(dataIndex, { type: "number", operation: selectedOps, value });
957
+ }, [selectedOps, value]);
958
+ const handleKeyPress = (e) => {
959
+ const inputEvent = e.nativeEvent;
960
+ if (!/^\d*$/.test(inputEvent.data ?? "")) {
961
+ e.preventDefault();
962
+ }
963
+ };
964
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "ms-form-item", children: [
965
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("label", { children: title }),
966
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "", children: [
967
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Select_default, { option: options, onChange: (e) => setSelectedOps(e.target.value), value: selectedOps }),
968
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
969
+ Input_default,
970
+ {
971
+ name: dataIndex,
972
+ onChange: (e) => setValue(e.target.value),
973
+ value,
974
+ onBeforeInput: handleKeyPress
975
+ }
976
+ )
977
+ ] })
978
+ ] });
979
+ };
980
+ var NumberFilter_default = NumberFilter;
981
+
982
+ // src/components/Filter/Date/DateFilter.tsx
983
+ var import_react9 = require("react");
984
+ var import_jsx_runtime16 = require("react/jsx-runtime");
985
+ var DateFilter = (colConfig) => {
986
+ const { title, dataIndex, onChange, filterOps, type } = colConfig;
987
+ const [selectedOps, setSelectedOps] = (0, import_react9.useState)("=");
988
+ const [[fromDate, toDate], setValue] = (0, import_react9.useState)(["", ""]);
989
+ const options = [
990
+ {
991
+ label: "Equal to",
992
+ value: "="
993
+ },
994
+ {
995
+ label: "No Equal to",
996
+ value: "!="
997
+ },
998
+ {
999
+ label: "After",
1000
+ value: ">"
1001
+ },
1002
+ {
1003
+ label: "Before",
1004
+ value: "<"
1005
+ },
1006
+ {
1007
+ label: "Range",
1008
+ value: "<>"
1009
+ }
1010
+ ];
1011
+ (0, import_react9.useEffect)(() => {
1012
+ if (filterOps === void 0) {
1013
+ setSelectedOps("=");
1014
+ setValue(["", ""]);
1015
+ } else {
1016
+ setSelectedOps(filterOps.operation);
1017
+ setValue(filterOps.value);
1018
+ }
1019
+ }, [filterOps]);
1020
+ const handleChange = (e) => {
1021
+ const value = e.target.value;
1022
+ setSelectedOps(value);
1023
+ onChange(dataIndex, { type, operation: value, value: [fromDate, toDate] });
1024
+ };
1025
+ const handleDateSelect = (e) => {
1026
+ let { name, value } = e.target;
1027
+ if (name == "from") {
1028
+ setValue([value, toDate]);
1029
+ onChange(dataIndex, { type, operation: selectedOps, value: [value, toDate] });
1030
+ } else {
1031
+ setValue([fromDate, value]);
1032
+ onChange(dataIndex, { type, operation: selectedOps, value: [fromDate, value] });
1033
+ }
1034
+ };
1035
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "ms-form-item", children: [
1036
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("label", { children: title }),
1037
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Select_default, { name: dataIndex, option: options, onChange: handleChange }),
1038
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Input_default, { name: "from", type: "date", onChange: handleDateSelect, value: fromDate, max: toDate ? new Date(toDate).toISOString().split("T")[0] : void 0 }),
1039
+ selectedOps == "<>" && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
1040
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "text-center ms-range-icon", children: rangeIcon }),
1041
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Input_default, { name: `to`, type: "date", onChange: handleDateSelect, value: toDate, min: fromDate ? new Date(fromDate).toISOString().split("T")[0] : void 0 })
1042
+ ] })
1043
+ ] });
1044
+ };
1045
+ var DateFilter_default = DateFilter;
1046
+
1047
+ // src/components/Filter/Boolean/BooleanFilter.tsx
1048
+ var import_react10 = require("react");
1049
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1050
+ var BooleanFilter = (colConfig) => {
1051
+ const { title, dataIndex, onChange, filterOps, displayAs } = colConfig;
1052
+ const [selectedOps, setSelectedOps] = (0, import_react10.useState)("=");
1053
+ const [value, setValue] = (0, import_react10.useState)("");
1054
+ (0, import_react10.useEffect)(() => {
1055
+ if (filterOps === void 0) {
1056
+ setSelectedOps("=");
1057
+ setValue("");
1058
+ } else {
1059
+ setSelectedOps(filterOps.operation);
1060
+ setValue(filterOps.value);
1061
+ }
1062
+ }, []);
1063
+ (0, import_react10.useEffect)(() => {
1064
+ if (filterOps?.value)
1065
+ setValue(filterOps?.value);
1066
+ }, [filterOps?.value]);
1067
+ const handleSelection = (e) => {
1068
+ setValue(e.target.value);
1069
+ onChange(dataIndex, { type: "boolean", operation: "=", value: e.target.value });
1070
+ };
1071
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "ms-form-item", children: [
1072
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("label", { children: title }),
1073
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
1074
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "ms-radio-group", children: [
1075
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "ms-radio-item", children: [
1076
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Input_default, { name: dataIndex, type: "radio", id: dataIndex + "_true", value: "true", className: "ms-table-radio", onChange: handleSelection, checked: value == "true" }),
1077
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { htmlFor: dataIndex + "_true", children: [
1078
+ " ",
1079
+ displayAs ? displayAs.true : "True"
1080
+ ] })
1081
+ ] }),
1082
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "ms-radio-item", children: [
1083
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Input_default, { name: dataIndex, type: "radio", id: dataIndex + "_false", value: "false", className: "ms-table-radio", onChange: handleSelection, checked: value == "false" }),
1084
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { htmlFor: dataIndex + "_false", children: [
1085
+ " ",
1086
+ displayAs ? displayAs.false : "False"
1087
+ ] })
1088
+ ] })
1089
+ ] }),
1090
+ value !== "" && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { title: "clear", className: "ms-table-clear-item", onClick: () => {
1091
+ setValue("");
1092
+ onChange(dataIndex, { type: "boolean", operation: "=", value: "" });
1093
+ }, children: closeIcon })
1094
+ ] })
1095
+ ] });
1096
+ };
1097
+ var BooleanFilter_default = BooleanFilter;
1098
+
1099
+ // src/components/Filter/FilterModal.tsx
1100
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1101
+ var FilterModal = (props) => {
1102
+ const filterRef = (0, import_react11.useRef)(null);
1103
+ const headerRef = (0, import_react11.useRef)(null);
1104
+ const footerRef = (0, import_react11.useRef)(null);
1105
+ const [height, setHeight] = (0, import_react11.useState)(0);
1106
+ const [show, toggleShow] = (0, import_react11.useState)(false);
1107
+ const { state: { colConfigs, filters }, api: { onFilterApply } } = useTable();
1108
+ const [filterValues, setFilterValues] = (0, import_react11.useState)({});
1109
+ (0, import_react11.useEffect)(() => {
1110
+ let ref = props.containerRef;
1111
+ let totalHeight = ref?.current.clientHeight || 200;
1112
+ let headerHeight = headerRef?.current.clientHeight || 35;
1113
+ let footerHeight = footerRef?.current.clientHeight || 35;
1114
+ setHeight(totalHeight + 20 - headerHeight - footerHeight);
1115
+ }, []);
1116
+ (0, import_react11.useEffect)(() => {
1117
+ function handleClickOutside(event) {
1118
+ if (!props.isVisible)
1119
+ return;
1120
+ if (filterRef && "current" in filterRef && filterRef.current && !filterRef.current.contains(event.target)) {
1121
+ toggleShow(false);
1122
+ setTimeout(() => {
1123
+ props.toggleFilterModal(false);
1124
+ setFilterValues({});
1125
+ }, 300);
1126
+ }
1127
+ }
1128
+ document.addEventListener("mousedown", handleClickOutside);
1129
+ return () => document.removeEventListener("mousedown", handleClickOutside);
1130
+ }, [filterRef, props.toggleFilterModal]);
1131
+ const onChangeFilterItems = (0, import_react11.useCallback)((dataIndex, value) => {
1132
+ if (value.value == "") {
1133
+ let newFilter = {};
1134
+ for (let key in filterValues) {
1135
+ if (key != dataIndex) {
1136
+ newFilter[key] = filterValues[key];
1137
+ }
1138
+ }
1139
+ setFilterValues(newFilter);
1140
+ return;
1141
+ }
1142
+ setFilterValues((prev) => ({
1143
+ ...prev,
1144
+ [dataIndex]: value
1145
+ }));
1146
+ }, []);
1147
+ (0, import_react11.useEffect)(() => {
1148
+ if (Object.keys(filters).length > 0) {
1149
+ setFilterValues(filters);
1150
+ }
1151
+ }, [filters]);
1152
+ const renderFieldItem = (colConfig) => {
1153
+ if (colConfig.isHidden || !colConfig.isFilterEnabled) {
1154
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, {});
1155
+ }
1156
+ switch (colConfig.type) {
1157
+ case "string":
1158
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TextFilter_default, { ...colConfig, onChange: onChangeFilterItems, filterOps: filterValues[colConfig.dataIndex] }, `text_ ${colConfig.dataIndex}`);
1159
+ case "date":
1160
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DateFilter_default, { ...colConfig, onChange: onChangeFilterItems, filterOps: filterValues[colConfig.dataIndex] }, `date_ ${colConfig.dataIndex}`);
1161
+ case "number":
1162
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(NumberFilter_default, { ...colConfig, onChange: onChangeFilterItems, filterOps: filterValues[colConfig.dataIndex] }, `numvber_ ${colConfig.dataIndex}`);
1163
+ case "boolean":
1164
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BooleanFilter_default, { ...colConfig, onChange: onChangeFilterItems, filterOps: filterValues[colConfig.dataIndex] }, `numvber_ ${colConfig.dataIndex}`);
1165
+ default:
1166
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, {});
1167
+ }
1168
+ };
1169
+ const ClearAllFilterItems = () => {
1170
+ setFilterValues({});
1171
+ onFilterApply({});
1172
+ };
1173
+ const handleApply = () => {
1174
+ onFilterApply(filterValues);
1175
+ };
1176
+ (0, import_react11.useEffect)(() => {
1177
+ if (props.isVisible) {
1178
+ setTimeout(() => toggleShow(true), 100);
1179
+ }
1180
+ }, [props.isVisible]);
1181
+ const onFilterModal = () => {
1182
+ toggleShow(false);
1183
+ setTimeout(() => {
1184
+ props.toggleFilterModal(false);
1185
+ }, 300);
1186
+ };
1187
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "filter-modal", style: show ? { right: "5px" } : {}, ref: filterRef, children: [
1188
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "filter-header", ref: headerRef, children: [
1189
+ "Filter",
1190
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "close", onClick: onFilterModal, children: closeIcon })
1191
+ ] }),
1192
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "filter-body", style: { height }, children: colConfigs.map((col) => {
1193
+ return renderFieldItem(col);
1194
+ }) }),
1195
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "filter-footer", ref: footerRef, children: [
1196
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Button_default, { label: "Apply", className: "", disabled: Object.keys(filterValues).length > 0 ? false : true, onClick: handleApply }),
1197
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Button_default, { label: "Clear All", className: "ms-table-btn-default", style: { marginLeft: "5px" }, disabled: Object.keys(filterValues).length > 0 ? false : true, onClick: ClearAllFilterItems })
1198
+ ] })
1199
+ ] });
1200
+ };
1201
+ var FilterModal_default = (0, import_react11.memo)(FilterModal);
1202
+
1203
+ // src/components/Loader.tsx
1204
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1205
+ var Loader = () => {
1206
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "ms-loader-wrapper", children: [
1207
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "ms-loader-overlay" }),
1208
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "ms-loader" }),
1209
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { children: "Loading..." })
1210
+ ] });
1211
+ };
1212
+ var Loader_default = Loader;
1213
+
496
1214
  // src/MsReactTable.tsx
497
- var import_jsx_runtime10 = require("react/jsx-runtime");
1215
+ var import_jsx_runtime20 = require("react/jsx-runtime");
498
1216
  var MsReactTable = (props) => {
499
- const { showPagination = true } = props;
500
- const containerRef = import_react5.default.useRef(null);
501
- const tbodyRef = import_react5.default.useRef(null);
502
- const theadRef = import_react5.default.useRef(null);
503
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(TableProvider, { ...props, tbodyRef, theadRef, children: [
504
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "table-container", ref: containerRef, style: { height: props.height || "200px" }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("table", { ref: props.ref, className: `ms-react-table ${props.className}`, border: 0, cellPadding: 0, cellSpacing: 0, style: { width: "100%", ...props.style }, children: [
505
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(msTableHeader_default, { ref: theadRef }),
506
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(msTableBody_default, { ref: tbodyRef })
1217
+ const { showPagination = true, ref, isLoading } = props;
1218
+ const containerRef = import_react12.default.useRef(null);
1219
+ const tbodyRef = import_react12.default.useRef(null);
1220
+ const theadRef = import_react12.default.useRef(null);
1221
+ const [showModalFilter, toggleModalFilter] = import_react12.default.useState(false);
1222
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(TableProvider, { ...props, ref, tContainerRef: containerRef, theadRef, toggleModalFilter, children: [
1223
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "ms-table-container", ref: containerRef, style: { height: props.height || "200px" }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("table", { className: `ms-react-table ${props.className}`, border: 0, cellPadding: 0, cellSpacing: 0, style: { width: "100%", ...props.style }, children: [
1224
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(msTableHeader_default, { ref: theadRef }),
1225
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(msTableBody_default, { ref: tbodyRef })
507
1226
  ] }) }),
508
- showPagination && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(msTableFooter_default, {})
1227
+ showPagination && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(msTableFooter_default, { toggleFilterModal: toggleModalFilter }),
1228
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { children: [
1229
+ showModalFilter && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(FilterModal_default, { isVisible: showModalFilter, toggleFilterModal: toggleModalFilter, containerRef }),
1230
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "ms-overlay", style: showModalFilter ? { width: "100%" } : {} }),
1231
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Loader_default, {})
1232
+ ] })
509
1233
  ] });
510
1234
  };
511
1235
  MsReactTable.displayName = "MsReactTable";
512
1236
  var MsReactTable_default = MsReactTable;
513
- // Annotate the CommonJS export names for ESM import in node:
514
- 0 && (module.exports = {
515
- MsReactTable
516
- });
517
1237
  //# sourceMappingURL=index.js.map