akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 878 forks source link

Overriding default Sorting & Filtering logic for nested JSON as source. #930

Open TejinderEvry opened 5 years ago

TejinderEvry commented 5 years ago

Hi, I have nested JSON which i am passing to smart-table. I am setting my columns as follows:

this.gridSettings.columns['exceptionType'] = {
      title: 'exceptionType',
      editable: false
    };
    this.gridSettings.columns['exceptionDescription'] = {
      title: 'exceptionDescription',
      editable: false,
      width: '20%',
    };
    this.gridSettings.columns['employment.employeeName'] = {
      title: 'employeeName',
      editable: false,
      valuePrepareFunction: (cell: any, row: any) => row.employment.employeeName
    };
    this.gridSettings.columns['employment.postCode] = {
      title: 'postCode',
      editable: false,
      valuePrepareFunction: (cell: any, row: any) => row.employment.postCode
    };

The 'gridSettings' are normal settings for the ng2-smart-table defined as:

this.gridSettings = {
      pager: {
        display: true,
        perPage: 50
      },
      mode: 'external',
      reset: true,
      actions: {
        add: false,
        position: 'right',
        edit: false,
        delete: false,
        columnTitle: '',
      },
      noDataMessage: this._translate.instant('EventViewer.NoDataMsg'),
      columns: {}
    };

So the data binding is happening correctly. The issue is sorting & filtering for the nested objects. I have also solved same by modifying code of local.filter.js & local.sorter.js inside the node_modules. But changing those files will not be good idea. So can anyone here give some good suggestions to override the default sorting and filtering for my purpose. @akveo-private @akveo-bot

Thanks for reading 👍

lenichols commented 5 years ago

Having the same issue except im sorting currency in column and it doesnt sort properly.