Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created February 9, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/1f4bc2391c72f2e37ff1ea97210af605 to your computer and use it in GitHub Desktop.
Save arun12209/1f4bc2391c72f2e37ff1ea97210af605 to your computer and use it in GitHub Desktop.
({
FilterRecords: function(component) {
//data showing in table
var data = component.get("v.data");
// all data featched from apex when component loaded
var allData = component.get("v.UnfilteredData");
//Search tems
var searchKey = component.get("v.filter");
// check is data is not undefined and its lenght is greater than 0
if(data!=undefined || data.length>0){
// filter method create a new array tha pass the test (provided as function)
var filtereddata = allData.filter(word => (!searchKey) || word.Name.toLowerCase().indexOf(searchKey.toLowerCase()) > -1);
console.log('** '+filtereddata);
}
// set new filtered array value to data showing in the table.
component.set("v.data", filtereddata);
// check if searchKey is blank
if(searchKey==''){
// set unfiltered data to data in the table.
component.set("v.data",component.get("v.UnfilteredData"));
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment