[V 4.0.4] - Kendo Grid Event on view selection change

Posted by IramK on 25-Apr-2016 06:21

Hello,

On the main records list page of any object, the list is a kendo grid. I am carrying out some DOM manipulations when the grid (record list) is loaded. I am using the "databound" event to perform my manipulations after the grid is loaded. However when I change my view to View 2 and come back to this original view View 1, the DOM manipulations don't fire again. Could someone point out to me as to what event is fired when a view is changed for the records list view page?

Cheers.

Iram

Posted by IramK on 25-Apr-2016 10:43

Hello Vimal,

I found a solution to this. Just modified the code below to get it to work as expected. I had to perform a grid read before calling the dataBoundEventHandler() so that it carries out all processing again. It all works now.

<script>

 $(document).on(rb.newui.util.customEvents.rbs_viewSelectorChange,function(){

var grid = $("#" + $("section[name='Section1']").find(".rbs-grid").attr("id")).data("kendoGrid");
var gridID = $("section[name='Section1']").find(".rbs-grid").attr("id");

grid.dataSource.read();

dataBoundEventHandler();
});
</script>

Cheers.

Iram

All Replies

Posted by Vimalkumar Selvaraj on 25-Apr-2016 07:03

Hi Iram,

We fire following custom event when user switches view.

"rb.newui.util.customEvents.rbs_viewSelectorChange"

How ever this event fired after Kendo Grid initialization, so there is a possibility that  if you listen for view change event first time your "dataBound" event may not get called because Grid Data Binding might be finished by the time view switch event is fired .

You can give a try with following code snippet

<script>

 $(document).on(rb.newui.util.customEvents.rbs_viewSelectorChange,function(){

    dataBoundEventHandler();

 });

function dataBoundEventHandler(){

 var pageComponent = rb.newui.page.PageContext.getPageComponent(7773); //7773- cellID get from Page Design

 if(pageComponent && (typeof pageComponent.getKendoConfig=== 'function')){

    var kendoConfig = pageComponent.getKendoConfig();

    if(kendoConfig){

        kendoConfig.bind('dataBound',function(){ console.log('Data Bound event')});

    }

 }

}

//attach first time handler

dataBoundEventHandler();

</script>

Thanks,

Vimal

Posted by IramK on 25-Apr-2016 08:13

Hello Vimal,

Thanks for the above code. The viewSelectorChange event does fire, but my code in the dataBound event function doesn't get fired upon change of View. Any suggestions?

Cheers.

Iram

Posted by IramK on 25-Apr-2016 10:43

Hello Vimal,

I found a solution to this. Just modified the code below to get it to work as expected. I had to perform a grid read before calling the dataBoundEventHandler() so that it carries out all processing again. It all works now.

<script>

 $(document).on(rb.newui.util.customEvents.rbs_viewSelectorChange,function(){

var grid = $("#" + $("section[name='Section1']").find(".rbs-grid").attr("id")).data("kendoGrid");
var gridID = $("section[name='Section1']").find(".rbs-grid").attr("id");

grid.dataSource.read();

dataBoundEventHandler();
});
</script>

Cheers.

Iram

Posted by Vimalkumar Selvaraj on 25-Apr-2016 10:58

Hi Iram,

Sorry for delayed response. I am glad you made it work. But to be clear when "rb.newui.util.customEvents.rbs_viewSelectorChange" event is fired after Kendo Grid initialization . We do dataSource.read() after grid initialization is done so when you listen for view change event dataBound would have been fired already that's why you couldn't get hold of it. But if you have more than one pages of records in your list, when you switch between pages you will get call back to dataBound handler. So ideally you miss first dataBound event when you listen for view change event.

So your grid.dataSource.read() would make one more data fetch call for current page and you get a callback to your dataBound event. That's how it worked for you.

One more suggestion I would like to add , you can use our client side SDK to get kendoGrid instance as suggested in my code on my previous post for compatibility purpose. We recommend customer to use our API instead of using jQuery selector as this may get change in future releases.

Thanks,

Vimal.

Posted by IramK on 25-Apr-2016 11:03

Thanks for the explanation and will use the client side SDK.

Cheers.

Iram

This thread is closed