Search code examples
javascripthtmldatatablefilteringwebix

Filtering column's collection


In my Webix datatable one column fetches the data from the DataColletion. The problem is in the column's filtering: seems like it works with the original data (that contains the ID) and ignores the value of the data collection. How can I change this behavior and filter datatable by the collection's value?

Data:

var mycollection = new webix.DataCollection({  
  data:[{
    id: '12',
    value: 'CollItem 1'
  }]
});

var mydata = [{
  id: 1, 
  name: 'Item 1', 
  troublesomeColumn: '12' // id of the CollItem 1
}];

Config:

columns:[{
  id: 'troublesomeColumn',
  collection: mycollection,
  header:{
    content:"textFilter"
  }
}],
data:mydata

Code snippet. Thanks in advance.


Solution

  • Filters work with the dataset, not with the templates or values from the linked collections. Therefore, you need to create a custom filtering rule as described in the Webix Docs, i.e. define the needed pattern in the compareproperty of the filter:

      {
        content:"textFilter",
        compare:function(value, filter, obj){
          var colValue = mycollection.getItem(value).value;
          toFilter = colValue.toString().toLowerCase();                            
          filter = filter.toString().toLowerCase();
          return toFilter.indexOf(filter) !== -1;
        }
      }
    

    Updated snippet