How can I add a search box to a dashboard to filter the results?

Michael Lovell
Tera Guru

I have a widget on a dashboard which shows a report of open requests.  I would like to add a search box to filter the request list.  I have tried adding a Content Block widget, but the list values are not filtering. When I enter a value into the content block search field, the screen flashes like it is filtering, but all of the same values are returned.

The table name is 'u_itam2'

The field name to filter by is 'u_product_name'

The code for the content block is:T

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>

 var dbh = new DashboardMessageHandler("");

 function doSearch(evt){
       if (evt === true || evt.which == 13){
   			var searchValue = $j('#itamSearch').val();
			if (searchValue.startsWith("*"))
				dbh.publishFilter('u_itam2','u_product_nameLIKE' + searchValue.replace("*",""));
			else
				dbh.publishFilter('u_itam2', 'u_product_nameSTARTSWITH' + searchValue);
		}
}

</script>

<div class="input-group">
   <input id="itamSearch" class="form-control" 
       type="search" 
       onkeyup="doSearch(event)" 
       placeholder="ITAM Product Name contains" />     
   <span class="input-group-btn">
   <button type="button" class="btn btn-primary" onclick="doSearch(true)">
   <span class="glyphicon glyphicon-search"></span>
   </button>
     </span>
</div>
</j:jelly>

 

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

you could look at (custominteractive filters.

 

Regards,

Sachin

Thank you sachin.namjoshi,

 

I've tried adding the example filter from the custom interactive filter link.  I replaced "task" with my table's name.  I have a dashboard with an "All requests" report which renders 122 records when the dashboard loads.  I added the test filter and configured the report widget to "Follow interactive filter".  When I click the "Only mine" button or the "All tasks" button, the same 122 records are displayed.

I have a list of 1000 unique catalog items. How would I filter that without creating a filter of 1000 checkboxes?

Shivanjan Sain2
Tera Contributor

I am not sure, if your issue is resolved. I see this post as still not resolved.

The problem is with the code:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>

var dbh = new DashboardMessageHandler("search_id");

function publishFilter() {

        var filter_message = {};
        filter_message.id = "search_id";
        filter_message.table = "u_itam2";

        var searchValue = $j('#itamSearch').val();

        filter_message.filter = 'u_product_nameLIKE' + searchValue;
        // filter_message.filter += '^OR#ANY OTHER FIELD NAME#LIKE' + searchValue;
                // If you want to search any other field in the report, add the system name in the #ANY OTHER FIELD NAME# section
                // In this code, for all cases the stytem is doing a contains search. You can change the logic, based on the filter query that you like.

        SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);

        dbh.publishFilter(filter_message.table,filter_message.filter);
}

</script>

<!-- **** HTML Search Code Starts here **** -->

<div class="input-group">
<input id="itamSearch" class="form-control" 
        type="search" 
        onkeyup="publishFilter()" 
        placeholder="ITAM Product Name" />     
<span class="input-group-btn">
<button type="button" class="btn btn-primary" onclick="publishFilter()">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</j:jelly>

 

 

Please mark the post as resolved and my suggestion as helpful, if it work for you. All the best.