Hi, I am trying to get the amount of returned results from a search. What is the best way of achieving this?
I have tried counting the returned table rows but is inconsistent between returned results and no results found.
I tried this as a test:
rbf_getCount2(10930, 'starts with', 'Micro', function cb(values){alert(values.length);});
but get undefined as a result.
1. Edit the list view and go to "Totals and Subtotals" section > Specify the object name for counting.
2. After saving the list view this will add new rows at the bottom part says Grand total, beside it the # or record rows in the list. Now, in your search result page specify the code below.
<script> $(document).ready(function() { var x = $("tr.listItem:last td.rbs_listSummaryNumber:eq(1)").text(); if(parseInt(x) > 0) { alert("There are results: "+x); } else { alert("NO results: "+x); } }); </script>
---------------ANOTHER WAY---------------
If you don't need the # or rows and just simply identify whether there are results, you can use the code below into your search result page.
<script> $(document).ready(function() { var x = $("tr.listItem").length; if(x > 0) alert("There are results"); else alert("NO results"); }); </script>
Hope this may help.
Regards,
Orchid
Hi Byron,
You mean amount is a decimal field and when doing search you want to get the total of its column?
Regards,
Orchid
Didnt explain well, functional example:
On Account --> Records List Account I have a detailed search, after searching you get redirected to the Search Results Account page with list of matches. I want to count the number of rows returned and do something if there are no results returned and something else if there are results returned. Basically a record count.
I see, you have to create a detailed search too in the search result page then by code get the value of the field being filtered and assign that value the rbf_getCount2.
- Below image is a search result page, I also specified a detailed search above the list.
- When a user click the search button it takes over the value in the search field so there you assign that value the getCount. See code below, it works for me.
Note: It only works for "equal" and not for "contains"
<script> var filterVal = $("input[name='opValueDet1']").val(); rbf_getCount2("137279", "product_code", filterVal, function(data) { alert(data); }); </script>
Hope this may help.
Regards,
Orchid
Thanks Orchid
Would there be an alternate solution for "starts with" or "contains" as we do not have one condition with "equal" as exact match searching isnt practical. I just really want the number or rows returned and display a message accordingly.
Here is our scenario:
Accounts:
After searching you get redirected to the Search results:
Now if there are no records to display (as above) then I would like to display a message with a different button, if there are results I would like to display a message with the above button.
Hi Byron,
You mean amount is a decimal field and when doing search you want to get the total of its column?
Regards,
Orchid
Flag this post as spam/abuse.
1. Edit the list view and go to "Totals and Subtotals" section > Specify the object name for counting.
2. After saving the list view this will add new rows at the bottom part says Grand total, beside it the # or record rows in the list. Now, in your search result page specify the code below.
<script> $(document).ready(function() { var x = $("tr.listItem:last td.rbs_listSummaryNumber:eq(1)").text(); if(parseInt(x) > 0) { alert("There are results: "+x); } else { alert("NO results: "+x); } }); </script>
---------------ANOTHER WAY---------------
If you don't need the # or rows and just simply identify whether there are results, you can use the code below into your search result page.
<script> $(document).ready(function() { var x = $("tr.listItem").length; if(x > 0) alert("There are results"); else alert("NO results"); }); </script>
Hope this may help.
Regards,
Orchid
Very nice thank you :-)
You're welcome!
Cheers,
Orchid