@sd-angular/core 1.0.1 → 1.0.5

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.
@@ -1243,26 +1243,28 @@ class SdGridMaterial {
1243
1243
  });
1244
1244
  _filterLocal.set(this, (localItems, filterInfo) => {
1245
1245
  const { columns } = this.gridOption;
1246
+ const { rawColumnFilter, orderBy, orderDirection, pageSize, pageNumber } = filterInfo;
1246
1247
  const items = localItems.filter(item => {
1247
- var _a, _b;
1248
+ var _a, _b, _c, _d;
1248
1249
  for (const column of columns) {
1249
- const filterValue = (filterInfo.rawColumnFilter[column.field] || '').toString().trim().toLowerCase();
1250
- const columnValue = (item[column.field] || '').toString().trim().toLowerCase();
1250
+ const { field, type } = column;
1251
+ const filterValue = (rawColumnFilter[field] || '').toString().trim().toLowerCase();
1252
+ const columnValue = (item[field] || '').toString().trim().toLowerCase();
1251
1253
  if (filterValue) {
1252
- if (!columnValue) {
1254
+ if (!columnValue && type !== 'datetime' && type !== 'date' && type !== 'time') {
1253
1255
  return false;
1254
1256
  }
1255
- if (column.type === 'string') {
1257
+ if (type === 'string') {
1256
1258
  if (columnValue.indexOf(filterValue) === -1) {
1257
1259
  return false;
1258
1260
  }
1259
1261
  }
1260
- else if (column.type === 'values') {
1262
+ else if (type === 'values') {
1261
1263
  if (columnValue !== filterValue) {
1262
1264
  return false;
1263
1265
  }
1264
1266
  }
1265
- else if (column.type === 'number') {
1267
+ else if (type === 'number') {
1266
1268
  const fValue = +filterValue.replace('>=', '').replace('<=', '').replace('>', '').replace('<', '');
1267
1269
  const cValue = +columnValue;
1268
1270
  if (fValue || fValue === 0) {
@@ -1286,7 +1288,7 @@ class SdGridMaterial {
1286
1288
  }
1287
1289
  }
1288
1290
  }
1289
- else if (column.type === 'bool') {
1291
+ else if (type === 'bool') {
1290
1292
  if (filterValue === '1' && columnValue !== '1' && columnValue !== 'true') {
1291
1293
  return false;
1292
1294
  }
@@ -1294,12 +1296,15 @@ class SdGridMaterial {
1294
1296
  return false;
1295
1297
  }
1296
1298
  }
1297
- else if (column.type === 'datetime' || column.type === 'date' || column.type === 'time') {
1298
- const from = (_a = filterInfo.rawColumnFilter[column.field]) === null || _a === void 0 ? void 0 : _a.from;
1299
- const to = (_b = filterInfo.rawColumnFilter[column.field]) === null || _b === void 0 ? void 0 : _b.to;
1299
+ else if (type === 'datetime' || type === 'date' || type === 'time') {
1300
+ const from = (_b = (_a = rawColumnFilter[field]) === null || _a === void 0 ? void 0 : _a.from) !== null && _b !== void 0 ? _b : rawColumnFilter[field];
1301
+ const to = (_d = (_c = rawColumnFilter[field]) === null || _c === void 0 ? void 0 : _c.to) !== null && _d !== void 0 ? _d : rawColumnFilter[field];
1300
1302
  const fromDate = Date.begin(from);
1301
1303
  const toDate = Date.end(to);
1302
1304
  if (fromDate && toDate) {
1305
+ if (!columnValue) {
1306
+ return false;
1307
+ }
1303
1308
  if (new Date(columnValue).getTime() < fromDate.getTime() || new Date(columnValue).getTime() >= toDate.getTime()) {
1304
1309
  return false;
1305
1310
  }
@@ -1310,8 +1315,8 @@ class SdGridMaterial {
1310
1315
  return true;
1311
1316
  });
1312
1317
  // Sort
1313
- if (filterInfo.orderBy && filterInfo.orderDirection) {
1314
- const column = columns.find(e => e.field === filterInfo.orderBy);
1318
+ if (orderBy && orderDirection) {
1319
+ const column = columns.find(e => e.field === orderBy);
1315
1320
  if (column) {
1316
1321
  const { type, field } = column;
1317
1322
  items.sort((current, next) => {
@@ -1333,18 +1338,15 @@ class SdGridMaterial {
1333
1338
  }
1334
1339
  return 0;
1335
1340
  });
1336
- if (filterInfo.orderDirection === 'desc') {
1341
+ if (orderDirection === 'desc') {
1337
1342
  items.reverse();
1338
1343
  }
1339
1344
  }
1340
1345
  }
1341
1346
  return {
1342
1347
  items: items.filter((item, index) => {
1343
- var _a, _b, _c, _d;
1344
- const pageIndex = ((_a = __classPrivateFieldGet(this, _paginator)) === null || _a === void 0 ? void 0 : _a.pageIndex) || 0;
1345
- const pageSize = ((_b = __classPrivateFieldGet(this, _paginator)) === null || _b === void 0 ? void 0 : _b.pageSize) || ((_d = (_c = this.gridOption) === null || _c === void 0 ? void 0 : _c.paginate) === null || _d === void 0 ? void 0 : _d.pageSize) || 50;
1346
- return index >= pageIndex * pageSize
1347
- && index < (pageIndex + 1) * pageSize;
1348
+ return index >= pageNumber * pageSize
1349
+ && index < (pageNumber + 1) * pageSize;
1348
1350
  }),
1349
1351
  total: items.length
1350
1352
  };
@@ -1361,7 +1363,7 @@ class SdGridMaterial {
1361
1363
  pageSize: ((_j = __classPrivateFieldGet(this, _paginator)) === null || _j === void 0 ? void 0 : _j.pageSize) || ((_l = (_k = this.gridOption) === null || _k === void 0 ? void 0 : _k.paginate) === null || _l === void 0 ? void 0 : _l.pageSize) || 50
1362
1364
  });
1363
1365
  });
1364
- _load$1.set(this, (filterReq) => __awaiter(this, void 0, void 0, function* () {
1366
+ _load$1.set(this, (filterReq, force = true) => __awaiter(this, void 0, void 0, function* () {
1365
1367
  this.isLoading = true;
1366
1368
  try {
1367
1369
  if (this.gridOption.type === 'server') {
@@ -1372,12 +1374,14 @@ class SdGridMaterial {
1372
1374
  return yield result;
1373
1375
  }
1374
1376
  else {
1375
- const results = this.gridOption.items();
1376
- if (results instanceof Promise) {
1377
- this.localItems = yield results;
1378
- }
1379
- else {
1380
- this.localItems = results;
1377
+ if (force) {
1378
+ const results = this.gridOption.items();
1379
+ if (results instanceof Promise) {
1380
+ this.localItems = yield results;
1381
+ }
1382
+ else {
1383
+ this.localItems = results;
1384
+ }
1381
1385
  }
1382
1386
  return __classPrivateFieldGet(this, _filterLocal).call(this, this.localItems, filterReq);
1383
1387
  }
@@ -1402,8 +1406,8 @@ class SdGridMaterial {
1402
1406
  this.isSelectAll = this.items.every(e => e.isSelected);
1403
1407
  __classPrivateFieldGet(this, _updateSelectedItems).call(this);
1404
1408
  }));
1405
- this.reload = () => __awaiter(this, void 0, void 0, function* () {
1406
- const data = yield __classPrivateFieldGet(this, _load$1).call(this, __classPrivateFieldGet(this, _getFilter).call(this));
1409
+ this.reload = (force = true) => __awaiter(this, void 0, void 0, function* () {
1410
+ const data = yield __classPrivateFieldGet(this, _load$1).call(this, __classPrivateFieldGet(this, _getFilter).call(this), force);
1407
1411
  __classPrivateFieldGet(this, _render).call(this, data);
1408
1412
  });
1409
1413
  _exportedItems.set(this, (pageNumber = 0, pageSize = 10000) => __awaiter(this, void 0, void 0, function* () {
@@ -1655,7 +1659,7 @@ class SdGridMaterial {
1655
1659
  });
1656
1660
  this.onFilterChange = () => {
1657
1661
  __classPrivateFieldGet(this, _paginator).pageIndex = 0;
1658
- this.reload();
1662
+ this.reload(false);
1659
1663
  };
1660
1664
  this.onExpand = (rowData) => __awaiter(this, void 0, void 0, function* () {
1661
1665
  var _q, _r, _s;
@@ -1901,7 +1905,7 @@ class SdGridMaterial {
1901
1905
  __classPrivateFieldGet(this, _subscription$1).add(gridFilter.filterChange.pipe(debounceTime(200), map(() => {
1902
1906
  __classPrivateFieldGet(this, _paginator).pageIndex = 0;
1903
1907
  return __classPrivateFieldGet(this, _getFilter).call(this);
1904
- }), switchMap(__classPrivateFieldGet(this, _load$1))).subscribe(__classPrivateFieldGet(this, _render)));
1908
+ }), switchMap(filterInfo => __classPrivateFieldGet(this, _load$1).call(this, filterInfo, false))).subscribe(__classPrivateFieldGet(this, _render)));
1905
1909
  }
1906
1910
  }
1907
1911
  set option(option) {
@@ -1924,13 +1928,13 @@ class SdGridMaterial {
1924
1928
  set paginator(paginator) {
1925
1929
  if (paginator && __classPrivateFieldGet(this, _paginator) !== paginator) {
1926
1930
  __classPrivateFieldSet(this, _paginator, paginator);
1927
- __classPrivateFieldGet(this, _subscription$1).add(paginator.page.pipe(debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(__classPrivateFieldGet(this, _load$1))).subscribe(__classPrivateFieldGet(this, _render)));
1931
+ __classPrivateFieldGet(this, _subscription$1).add(paginator.page.pipe(debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(filterInfo => __classPrivateFieldGet(this, _load$1).call(this, filterInfo, false))).subscribe(__classPrivateFieldGet(this, _render)));
1928
1932
  }
1929
1933
  }
1930
1934
  set sort(sort) {
1931
1935
  if (sort && __classPrivateFieldGet(this, _sort) !== sort) {
1932
1936
  __classPrivateFieldSet(this, _sort, sort);
1933
- __classPrivateFieldGet(this, _subscription$1).add(sort.sortChange.pipe(debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(__classPrivateFieldGet(this, _load$1))).subscribe(__classPrivateFieldGet(this, _render)));
1937
+ __classPrivateFieldGet(this, _subscription$1).add(sort.sortChange.pipe(debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(filterInfo => __classPrivateFieldGet(this, _load$1).call(this, filterInfo, false))).subscribe(__classPrivateFieldGet(this, _render)));
1934
1938
  }
1935
1939
  }
1936
1940
  ngOnInit() {
@@ -1940,7 +1944,7 @@ class SdGridMaterial {
1940
1944
  __classPrivateFieldGet(this, _subscription$1).add(this.sdCellDefs.changes.pipe(startWith([])).subscribe(__classPrivateFieldGet(this, _initCellDef)));
1941
1945
  __classPrivateFieldGet(this, _subscription$1).add(this.sdFooterDefs.changes.pipe(startWith([])).subscribe(__classPrivateFieldGet(this, _initFooterDef)));
1942
1946
  __classPrivateFieldGet(this, _subscription$1).add(this.sdFilterDefs.changes.pipe(startWith([])).subscribe(__classPrivateFieldGet(this, _initFilterDef)));
1943
- __classPrivateFieldGet(this, _subscription$1).add(__classPrivateFieldGet(this, _optionChanges).pipe(startWith({}), debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(__classPrivateFieldGet(this, _load$1))).subscribe(__classPrivateFieldGet(this, _render)));
1947
+ __classPrivateFieldGet(this, _subscription$1).add(__classPrivateFieldGet(this, _optionChanges).pipe(startWith({}), debounceTime(200), map(__classPrivateFieldGet(this, _getFilter)), switchMap(filterInfo => __classPrivateFieldGet(this, _load$1).call(this, filterInfo, true))).subscribe(__classPrivateFieldGet(this, _render)));
1944
1948
  this.ref.detectChanges();
1945
1949
  }
1946
1950
  ngOnDestroy() {