How to create a data table filter widget in Service Portal?

Arsh1
Tera Contributor

So I have created a data table widget using filter attribute in ng-repeat directive but the filtering is not working as expected.

Im attaching a picture to explain the issue clearly.

find_real_file.png

As you can see in this table there are different fields above different rows for filtering the data i.e. a number field, state field, short description and date field.

Now the problem is when im typing harry in number field its showing me the record with short description as harry but it shouldn't show me anything. So i need to acheive filtering on row level or a specific row. I will attach my code here as well

HTML:

<div class="container">
<div class="row">
<table id="myTable" class="table table-striped table-bordered">
<thead>
<tr>
<th><input id="myInput" type="text"
class="form-control"
placeholder="Search for an incident using number" ng-model=c.data.number
/>Number</th>
<th><select id="mySelect" ng-model="c.data.choice"
class="form-control">
<option value="">---empty---</option>
<option value="Pending">Pending</option>
<option value="Open">Open</option>
<option value="Work in Progress">Work in progress</option>
<option value="Ready">Ready</option>
<option value="Draft">Draft</option>
<option value="Closed Complete">Closed Complete</option>
<option value="Closed Incomplete">Closed Incomplete</option>
<option value="Closed Skipped">Closed Skipped</option>
</select>
State</th>
<th><input id="myInput3" type="text" ng-model="c.data.desc"
class="form-control"
placeholder="Search for an incident using Short Description"
/>Short description</th>
<!--<th><input id="MyDate" type="date" class="form-control" ng-model="c.data.date">Created On</th>-->
<th><sp-date-picker id="MyDate" field="MyDate" ng-model="c.data.date" ng-model-options="{getterSetter: true}"></sp-date-picker>Created On</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in data.items | filter: c.data.number | filter: c.data.choice | filter: c.data.desc | filter: c.data.date">
<td><a>{{item.number.display_value}}</a></td>
<td>{{item.state.display_value}}</td>
<td>{{item.short_description.display_value}}</td>
<td>{{item.sys_created_on.display_value}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<button type="button">Check Date</button>
 

Client Script:

function(spUtil, $scope, $rootScope) {
/* widget controller */
var c = this;

c.Mybtn2 = function()
{
//c.data.date

}


c.keyword='';
c.keyword1='';
c.keyword2='';

$scope.MyDate = {
displayValue: '',
value: '',
name: 'fromdate'
};

}

 

Server-Side code: 

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.fields = options.fields || 'number,state,short_description,sys_created_on';
data.items = getRecentIncidents();

var items2 = [];
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',gs.getUserID());
user.query();
while(user.next())
{
var obj2={};
gs.addInfoMessage(user.getValue('date_format'));
}

function getRecentIncidents()
{
var items = [];
var incidentGR = new GlideRecordSecure('x_455525_healthcar_test_table');
//incidentGR.setLimit(5);
incidentGR.orderByDesc('sys_created_on');
incidentGR.query();
while(incidentGR.next())
{
var obj ={};
$sp.getRecordElements(obj, incidentGR, data.fields);
items.push(obj);
}
return items;
}
})();

 

 

Any help would be really appreciated 🙂 .

4 REPLIES 4

Pranav Bhagat
Kilo Sage
Did you tried the Angular Search by filter? Example https://youtu.be/Kp8k-0PXI2E

Well yes Basically i have used Angular directive ng-repeat and used Filter attribute to filter the data. You can run my code in your instance and change the table. you will see

 

Ct111
Giga Sage

Hello ,

 

Have you checked the out of the box "My Request" widget which comes when you click on

top right on portal .

Once you go there there is search box near filters to Open and Closed which allows only

searchign to be done by number and if anything you put apart from this then it wont give 

any results....

 

Try to look at the code for that and emulate the same in your widget.

 

Mark my ANSWER as CORRECT and hELPFUL if it helps

SN Emy
Tera Guru

Hello Arsh,

Can you share how you fixed this issue?

Thanks,