Trying to revise filter of Data Table Widget

jamesmcwhinney
Giga Guru

I am trying to revise the filter on a data table widget based on an event from another widget.

The widget is refreshing, but its showing up blank.

Could anyone suggest what I might be doing wrong?

 

Client Script:

function ($scope, spUtil, $location, spAriaFocusManager) {
	$scope.$on('data_table.click', function(e, parms){
		var p = $scope.data.page_id || 'form';
		var s = {id: p, table: parms.table, sys_id: parms.sys_id, view: 'sp'};
		var newURL = $location.search(s);
		spAriaFocusManager.navigateToLink(newURL.url());
	});
	
	$scope.$on('rowclicked', function (e, item){
		$scope.data.str_releaseSysID = item.sys_id;
		$scope.server.update();
	});
	
	
}

Server Script:

(function(){
	/*  "use strict"; - linter issues */
	// populate the 'data' object
	var sp_page = $sp.getValue('sp_page');
	var pageGR = new GlideRecord('sp_page');
	pageGR.get(sp_page);
	data.page_id = pageGR.id.getDisplayValue();
	$sp.getValues(data);
	if (data.field_list) {
		data.fields_array = data.field_list.split(',');
	} else {
		data.field_list = $sp.getListColumns(data.table);
	}
	

	if (input) {
		var gr_release = new GlideRecord('rm_release');
		data.filter = "parent=" + input.str_releaseSysID;
		if(gr_release.get(input.str_releaseSysID)){
			data.title = "Features included in Release '" + gr_release.short_description + "'";
		}
		
	} else {
		var str_configItemSysID = $sp.getParameter("cmdb_ci_appl");//"b0e98c554fdbe600059876601310c7ef"; //ServiceNow Production
		//Get sysID of next release
		var gr_nextRelease = new GlideRecord('rm_release');
		gr_nextRelease.addQuery('cmdb_ci',str_configItemSysID);
		gr_nextRelease.query();
		gr_nextRelease.orderBy('end_date');
		if(gr_nextRelease.next()){
			data.title = "Features included in Release '" + gr_nextRelease.short_description + "'";
			data.filter = "parent=" + gr_nextRelease.sys_id;
		}
	}
	
	
	
	
	
	data.p = data.p || 1;
	data.o = data.o || $sp.getValue('order_by');
	data.d = data.d || $sp.getValue('order_direction');
	data.page_index = (data.p - 1);
	data.window_size = 10;
	data.window_start  = (data.page_index * data.window_size);
	data.window_end = (((data.page_index + 1) * data.window_size));
	data.table = 'rm_feature';
	

	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: data.title,
		show_breadcrumbs: false
	};
	data.dataTableWidget = $sp.getWidget('smse-widget-data-table', widgetParams);
})();

 

 

 

2 REPLIES 2

jamesmcwhinney
Giga Guru

 

Found a solution, here is what I did:

I have two custom widgets on the page, both of which are clones of "Data Table From Instance Definition".

  • Releases Widget (Allows a user to choose a release)
  • Features Widget (Shows the features within the selected release)

 

Client Script in my releases widget:

function ($scope, spUtil, $location, spAriaFocusManager) {
	$scope.$on('data_table.click', function(e, row){
	
		var params = [];
		params.filter = 'parent=' + row.sys_id;
		params.table = 'rm_feature';
		if(row.record.short_description != null){
			//Requires the short description column to be visible
			params.title = "Features included in Release '" + row.record.short_description.display_value + "'";
		} else {
			params.title = "Features included in Release '??'";	
		}
		$rootScope.$broadcast('updateTableFilter',params);

	});
}

When a release is selected, it catches the event "data_table.click" emitted from its associated OOTB widget "widget-data-table".

 

 

Client Script added to the OOTB widget "widget-data-table"

	

	$scope.$on('updateTableFilter', function(e, params){
		if(params.table == $scope.data.table){
			$scope.data.filter = params.filter;
			$scope.data.title = params.title;
			$scope.setSearch(false);	
		}
	});

 

Both "widget-data-table" widgets on the page hear the "updateTableFilter" event, but only the instance for the features table processes it.

The list of features are refreshed and the title is revised.

 

 

 

lss123
Tera Contributor

Hope this helps someone else, I struggled with this for a while but stumbled up this solution.  I just added this line of code to my client controller and the record list refreshed automatically:

$scope.$broadcast('widget-filter-breadcrumbs.queryModified', myEncodedQuery);