Search Support
-
Saroj PandaMarch 6, 2017 at 5:42 am #3943
The table has search() function to filter the contents, but how to use it to put filter on multiple columns in one table.
I tried to put two text control and added ${inbetalningar1}.search(0,potential, true, true) and ${inbetalningar1}.search(1,potential, true, true) on their On Input event, expecting when I have value on both filters then the table should list only rows which satisfy both filters.
But when I write anything in second textbox, the previous search result reset in table and filter it again based on input from second textbox.
Has anyone implemented multiple filters on SPARK tables? What is the best way to implemented this using SPARK controls?
Regards,
Saroj
SPARK SupportMarch 21, 2017 at 3:57 pm #4051Hi Saroj,
To filter the Table for multiple column values, create a search function to pass into the search method. The search method will pass the list item into your function. Compare a property of the list to some logic, and the return the list item to be pushed to the temporary filtered list.
Lets say that I have a Business Object of myComplexType with properties str1, str2, int1 and dec1 (String, String, Integer, Decimal). I can use this function to look for integer values matching greater than 14 and decimal values less than 18.0:
function mySearch2(listItem) {
if(listItem.int1 > 14 && listItem.dec1 < 18.0){
return listItem;}
}
Regards,
Stephen P.
Sidhartha PriyeApril 24, 2017 at 3:28 pm #4188Stephen,
In our case the requirement is I should be enter more than one search string in the search box and it should do a OR on the results returned from both the searches. Is this possible?
So in the example above I want to implement a search function like this (text1 and tex2 are properties of the complex BO) –
function mySearch2(listItem) {
if(listItem.text1 == “searchString1″ && listItem.text2 ==”searchString2”)
{return listItem;}
}
How do I pass the dynamic search strings (searchString1 and searchString2) into this search2 function?
Saroj PandaApril 25, 2017 at 7:22 am #4217Can you try accessing the search text control inside the function and do getText() for search text.
Regards,Saroj
Saroj PandaApril 25, 2017 at 9:08 am #4219This is an example of how I have done this using two Text fields “txtFilter1” and “txtFilter2”. I’m calling ${table1}.search(customSearch) on Blur event of each Text control.
<script>
function customSearch(listItem) {
//console.log(listItem);
var filter1 = page.ui.get("txtFilter1").getText();
filter1 = filter1? filter1:"";
var filter2 = page.ui.get("txtFilter2").getText();
filter2 = filter2? filter2.toUpperCase():""; // for case insensitive search
if(listItem.bookingDate.indexOf(filter1) > -1 && listItem.status.toUpperCase().indexOf(filter2) > -1) {
return listItem;
}
}
</script>
Regards,
Saroj
-
|
You must be logged in to reply to this topic.