Embedded (data table) widget is not refreshing after button clicking

Rajeshkumar1
Kilo Expert

Business:

My business is I have one button in "data table from instance definition" widget named as "Active" button, Whenever I click that button I need to show only active records, I am a beginner of service portal, So only I starting with basic works.

Issue:

Whenever I try to pass the filter condition via client side, That time the widget showing info message like"No records in".

Use the following image for reference:

find_real_file.png

I have found the root cause of the issue, But I still cannot able to find the solution for this. 

The root cause of the issue:

The embedded widget is not refreshing. (Here embedded widget is "widget-data-table")

data.dataTableWidget = $sp.getWidget('widget-data-table', widgetParams);

The embedded widget is only working one time. If you try and refresh the widget via the server it returns an empty data model.

The following scripts for your reference:

Client script:

var c = this;

$scope.activeRecord = function(){

c.data.filter ="active=true"
c.server.update();

spUtil.get("widget-data-table", answer).then(function(response) {

c.data.dataTableWidget = response;

});

}

Server script:

data.filter = input.filter;

data.table_label = gr.getLabel();
var widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
window_size: data.window_size,
view: options.view,
title: options.title,
show_breadcrumbs: false,
show_keywords: true
};
data.dataTableWidget = $sp.getWidget("widget-data-table", widgetParams);

})();

Html:

  <sp-widget ng-if="data.dataTableWidget"  widget="data.dataTableWidget"></sp-widget>

 

1 ACCEPTED SOLUTION

Rajeshkumar1
Kilo Expert

 

The following script is worked as I expected. We need to call the server side object into the client side using var params = $scope.data.widgetParams; [data.widgetParams], We can get the embedded widget using spUtill.get and we can send the response to that specific widget. 

Client script:

var c = this;


$scope.activeRecord = function(){

var params = $scope.data.widgetParams;

params.filter = "active=true";
spUtil.get('data_table_1',params).then(function(response){
$scope.data.dataTableWidget = response;
})

}

 

Server script:

var widgetParams;

data.table_label = gr.getLabel();
data.widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
window_size: data.window_size,
view: options.view,
title: options.title,
show_breadcrumbs: false
};
//gs.addInfoMessage("Filters"+data.widgetParams.filter);



//data.dataTableWidget = $sp.getWidget("data_table_1", widgetParams);

data.dataTableWidget = $sp.getWidget('data_table_1', data.widgetParams);

//data.dataTableWidget = $sp.getWidget('data_table_1', {filter: widgetParams.filter});

})();

 

 

View solution in original post

8 REPLIES 8

THIS should be the answer.  This simple 1-liner works wonders!  Thank you!

Thank you so much for sharing your solution! It's working like a charm! Awesome!

Alternative solution also working:

$scope.$broadcast('data_table.setFilter', myEncodedQuery);

Can you please post a full client and server side code? I am not getting as to why we need code on both side.

Can you please elaborate by providing full client and server side code? As per documentation we can use either server side or client side code then why we need both?