Created
February 9, 2019 17:51
-
-
Save arun12209/1f4bc2391c72f2e37ff1ea97210af605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
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