4.0.4 - Selection Event in a kendo Grid

Posted by Meryk on 12-Apr-2016 08:52

Hello,

I have a grid where I am doing some custom work on selection of a row. Which I am doing based on the onchange of checkboxes (the column on the left).

Now the issue I am facing is that the selection can be done through the 'select All' menu. In which case I still want to run my custom code (as it should run on any selection at the end, no matter if selected one by one or selected through that select all menu).

Is there a way to detect the click on that Select All menu?  Or how to detect the event of any selection in the grid ?

Thank you

Meryem

Posted by Thierry Ciot on 16-Apr-2016 13:33

Meryem,

Here is the full list of events as of V4.2:

rb.newui.util.customEvents = {

       'rbs_forceRelayout': 'rbs_forceRelayout',

       'rbs_uiResized': 'rbs_uiResized',

       'rbs_uiResizedInternal': 'rbs_uiResizedInternal',/* Added in V4.2 *//** This should only be used by platform code. This way any runtime issues in user configured handlers will not break platform code */

       "rbs_sectionExpanded": 'rbs_sectionExpanded',

       "rbs_sectionCollapsed": 'rbs_sectionCollapsed',

       "rbs_tabActivated": 'rbs_tabActivated',

       "rbs_viewSelectorChange": 'rbs_viewSelectorChange',

       "rbs_themeChange": "rbs_themeChange",

       "rbs_recordSelectionCleared": "rbs_recordSelectionCleared",

       "rbs_recordsSelected": "rbs_recordsSelected",

       "rbs_previewOpened": 'rbs_previewOpened',

       "rbs_previewClosed": 'rbs_previewClosed',

       "rbs_objectSelectedOnSelectorView": 'rbs_objectSelectedOnSelectorView',

       "rbs_pageRender": 'rbs_pageRender',

       "rbs_pageRenderInternal": 'rbs_pageRenderInternal', /** This should only be used by platform code pageRender handlers. This way any runtime issues in user configured handlers will not break platform code */

       "rbs_formDirtyStateChange":'rbs_formDirtyStateChange',

       "rbs_sessionExtended": 'rbs_sessionExtended',

       "rbs_logout": 'rbs_logout',

       "rbs_notificationDisplayed": 'rbs_notificationDisplayed', /* Added in V4.2 */

       "rbs_tabRender": 'rbs_tabRender', /* Added in V4.2 */

       "rbs_multiObjectSelectedOnSelectorView": 'rbs_multiObjectSelectedOnSelectorView' /* Added in V4.2 */

   };

Our documentation should have some content about all of these.

Thierry.

Posted by Vimalkumar Selvaraj on 15-Apr-2016 01:37

Yes we have for record deselection also. But this event fired only when all records get "deselected" .

Try this

 $(document).bind(rb.newui.util.customEvents.rbs_recordSelectionCleared,function(){

  });

Thanks,

Vimal.

All Replies

Posted by Meryk on 13-Apr-2016 05:40

Hi,

Any suggestions on this please?

Cheers,

Meryem

Posted by Vimalkumar Selvaraj on 13-Apr-2016 06:05

Hi Meryem,

We trigger custom event on successful record selection. Use below code to hook in your custom script

 $(document).bind(rb.newui.util.customEvents.rbs_recordsSelected,function(){

    alert('Record selected');

 });

But limitation is if you have more than one Grid in same the page and you perform selection on any grid this event get fired. So make sure when you use this event you don't have more than one Grid in the same page.

Please let me know if this helps.

Thanks,

Vimal.

Posted by Meryk on 14-Apr-2016 04:05

Hi Vimal,

Thanks for this. It is answering my question.

Is there a way I can get to the selected records from that event please?

Once the selection is done and this event triggered, what I need is to check some fields in the selected records to process .. So I need to know what are the selected records exactly.

Is that possible please?

Thank you

Meryem

Posted by Vimalkumar Selvaraj on 14-Apr-2016 05:10

Hi Meryem,

We don't have direct client side API to find selected records. However you can use our client side SDK to get KendoGrid config and find out selected records. I wrote a script for you ,

You should use original Id of your list which you can get from Page designer

$(document).bind(rb.newui.util.customEvents.rbs_recordsSelected,function(){

      var pageComp = rbf_getPageComponent(88681); //List original Id, get from Page Designer

      if(pageComp){

          var kendoConfig = pageComp.getKendoConfig(); // Get current Kendo Grid config

          if(kendoConfig){

             var records = kendoConfig.dataSource.view(); // Get current Kendo grid page records

             for(var i=0;i<records.length;i++){

                 var record = records[i]; //row record

                 if($('input[name="sel_'+record.recordId+'"]:checked').length > 0){ //If row is selected

                     console.log(record);

                 }

             }

          }

      }

 });

Hope this helps,

Thanks,

Vimal.

Posted by Meryk on 14-Apr-2016 05:52

Hi Vimal,

Ok I tried this, but I have an issue : rbf_getPageComponent is not defined in 4.0.4.

Has this method been introduced in a later version ?

I tried same thing in beta 4.2 and it is working.

Thank you

Meryem

Posted by Vimalkumar Selvaraj on 14-Apr-2016 06:00

Hi Meryem,

You are right, rbf_getPageComponent() introduced in later version. Just replace this method with below function, that should work for you. If you see issue with OriginalId in 4.0.4 please give a try with cellId..

rb.newui.page.PageContext.getPageComponent()

Thanks,

Vimal

Posted by Meryk on 14-Apr-2016 06:16

Thank you ! It is working now.

But do I have to change this to rbf_getPageComponent when we will upgrade to 4.2 then ?

Thanks

Meryem

Posted by Meryk on 14-Apr-2016 06:19

And Also, will that work for all the grid rows even if we have them on multiple pages ?

Posted by Meryk on 14-Apr-2016 06:33

Also from there, is there a way I can get to the values of all the fields displayed in the grid please ?

Posted by Vimalkumar Selvaraj on 14-Apr-2016 06:46

Hi Meryem,

Let me answer your question one by one

1)  do I have to change this to rbf_getPageComponent when we will upgrade to 4.2 then ? - No , you don't require to change it. rbf_getPageComponent() is a wrapper function which internally call "rb.newui.page.PageContext.getPageComponent()".

2) will that work for all the grid rows even if we have them on multiple pages ? -  Yes it will work

3) is there a way I can get to the values of all the fields displayed in the grid please ? -  Yes you can get it. In above code snippet i am logging the selected record in console.

if($('input[name="sel_'+record.recordId+'"]:checked').length > 0){ //If row is selected

        console.log(record);

}

record is the object which hold all fields data of row.

 

Thanks,

Vimal.

Posted by Meryk on 14-Apr-2016 09:01

Hi Vimal,

All good thank you.

Now, is there a way of catching the 'deselect' event as well please ?

Thanks

Meryem

Posted by Vimalkumar Selvaraj on 15-Apr-2016 01:37

Yes we have for record deselection also. But this event fired only when all records get "deselected" .

Try this

 $(document).bind(rb.newui.util.customEvents.rbs_recordSelectionCleared,function(){

  });

Thanks,

Vimal.

Posted by Thierry Ciot on 16-Apr-2016 13:33

Meryem,

Here is the full list of events as of V4.2:

rb.newui.util.customEvents = {

       'rbs_forceRelayout': 'rbs_forceRelayout',

       'rbs_uiResized': 'rbs_uiResized',

       'rbs_uiResizedInternal': 'rbs_uiResizedInternal',/* Added in V4.2 *//** This should only be used by platform code. This way any runtime issues in user configured handlers will not break platform code */

       "rbs_sectionExpanded": 'rbs_sectionExpanded',

       "rbs_sectionCollapsed": 'rbs_sectionCollapsed',

       "rbs_tabActivated": 'rbs_tabActivated',

       "rbs_viewSelectorChange": 'rbs_viewSelectorChange',

       "rbs_themeChange": "rbs_themeChange",

       "rbs_recordSelectionCleared": "rbs_recordSelectionCleared",

       "rbs_recordsSelected": "rbs_recordsSelected",

       "rbs_previewOpened": 'rbs_previewOpened',

       "rbs_previewClosed": 'rbs_previewClosed',

       "rbs_objectSelectedOnSelectorView": 'rbs_objectSelectedOnSelectorView',

       "rbs_pageRender": 'rbs_pageRender',

       "rbs_pageRenderInternal": 'rbs_pageRenderInternal', /** This should only be used by platform code pageRender handlers. This way any runtime issues in user configured handlers will not break platform code */

       "rbs_formDirtyStateChange":'rbs_formDirtyStateChange',

       "rbs_sessionExtended": 'rbs_sessionExtended',

       "rbs_logout": 'rbs_logout',

       "rbs_notificationDisplayed": 'rbs_notificationDisplayed', /* Added in V4.2 */

       "rbs_tabRender": 'rbs_tabRender', /* Added in V4.2 */

       "rbs_multiObjectSelectedOnSelectorView": 'rbs_multiObjectSelectedOnSelectorView' /* Added in V4.2 */

   };

Our documentation should have some content about all of these.

Thierry.

This thread is closed