How to add search filter to "Data Table from Instance Definition"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 02:34 PM
In CMS, end users could click the magnifying glass at the top of any table and set their search or filter criteria.
(eg. to filter their incidents, approval requests, or service requests)
In Service Portal, I cannot find any way to provide the same functionality to end users.
The "Data Table from Instance Definition" widget doesn't seem to have any comparable functionality such that an end user can easily filter their list.
After digging into it and opening a HI ticket, I found that the "Data Table from URL Definition" does allow user filtering.
Data Table from URL definition widget
It doesn't give you the ability to search via columns in the header, but it does allow the full filtering capability available in the main SN UI.
I was able to enable the filtering feature for the "Data Table from Instance Definition" via the following steps:
1. Clone the widget "Data Table from Instance Definition"
2. Add the below line "enable_filter: true" to the parameters passed to the widget-data-table in the server code:
var widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
window_size: data.window_size,
view: 'sp',
title: options.title,
show_breadcrumbs: true,
enable_filter: true
};
3. Update your instance references to target your custom "Data Table from Instance Definition"
The result is the below:
The one caveat I have found is that for some reason, default filters passed via the instance definition do cause the list to be filtered correctly, however if the user tries to edit their filters, the default filter does not appear in the condition editor as an active condition.
To work around this, I am just ensuring that any reference to this page (the page containing the widget) also includes the same parameters in the URL that were passed via the instance definition.
?id=approvals&table=sysapproval_approver&filter=approverDYNAMICjavascript:gs.getUserID()
Why not just use the "Data Table from URL Definition" at this point instead? I suppose that would be another option. I just wasnt crazy about the idea of allowing users to try look at any table by adjusting their URL. Maybe that's paranoid of me though...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 02:42 PM
You can do it in multiple ways.
In your widget instance, you can pass enable_filter: true as paramter.
Or, in your server script of Data Table from Instance Definition
Pass the parameter enable_filter: true to the data-table widget
var widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
window_size: data.window_size,
view: 'sp',
title: options.title,
show_breadcrumbs: true,
show_keywords: true,
color: 'default'
};
data.dataTableWidget = $sp.getWidget('data-table', widgetParams);
What I have done is I have created a clone of data-table and hardcoded enable_filter = 'true'
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 02:54 PM
Wow! you are quick on the draw! I hadnt even finished editing my post yet lol.
Thats exactly what I did, but I have found that for some reason the default filters dont show up in the search interface when you edit them.
I am working around it by passing them in the URL. Any ideas for a better approach?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 03:40 PM
Did you also pass show_breadcrumbs true?
var widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
window_size: data.window_size,
view: 'sp',
title: options.title,
show_breadcrumbs: true,
show_keywords: true,
color: 'default'
};
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2017 03:43 PM
Sorry. Not sure. It works for me..I can see the default filter when i edit it.
Please mark this response as correct or helpful if it assisted you with your question.