Use Data Table From Instance with a record watcher

Xif
Kilo Contributor

Hi Snow Community, 

Is it possible to use the widget Data Table widget from instance with a recordwatcher ? 

I'm actually inserting record though a button on our portal, and my list below display my data, but I have to refresh my page to see what I inserted

I cloned the widget Data Table From Instance and I added this into the client script but its not working

	spUtil.recordWatch($scope, "u_item_list", "", function(name, data) {
		spUtil.update($scope);
	});

Any one has a clue ? 

1 ACCEPTED SOLUTION

Your code seems correct. You may have to also take into account of the filters and order because they may need to be reset. I've attached my update set also if you can't get it working. 

View solution in original post

5 REPLIES 5

Lansford Hazel
Giga Expert

The easiest solution would be to refresh the page.


If you do not want to go along that, I would recommend using angulars $broadcast and $on functions to update the list. Record watcher, in this case, would be overkill due to it always watching for changes. When using $broadcast you isolate your API calls to only when an event has happened.

To achieve this you will need to broadcast the event has happened:

$scope.server.update().then(function(){
	$rootScope.$broadcast('sn-record-updated')
})

And then Listen with the following:

$scope.$on('sn-record-updated', function() {
		spUtil.update($scope);
})

 

Xif
Kilo Contributor

Hello LJ Hazel,

 

Thanks for your answer, I tried few version but I wasn't able to make it works,

 

Here my code : 

 

Widget #1:  (data table from instance client script)

 

function ($scope, spUtil, $location, spAriaFocusManager, $rootScope) {
	
	$scope.$on('sn-record-updated', function() {
		spUtil.update($scope);
});
		
	$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());


	});

}

Widget #2 : (were I insert my record on server side) 

function($scope, spUtil, $rootScope) {
	var c = this;
	

	
	c.uiAction = function(action) {
		c.data.action = action;
		c.server.update().then(function() {
			$rootScope.$broadcast('sn-record-updated');
			c.data.action = undefined;

		})
	}
}

 

But nothing happen, did I miss something ? 

Your code seems correct. You may have to also take into account of the filters and order because they may need to be reset. I've attached my update set also if you can't get it working. 

Thanks you so much for your help ! It works ! 

Its because i cloned the data table from instance, and not data table directly I think, anyway it works thanks !