Forums

Forums / Developing Portals / How to get selected item of Gridview by javascript

How to get selected item of Gridview by javascript

Thread is closed for posting
3 posts, 2 answered
  1. quanganh
    quanganh avatar
    33 posts
    Registered:
    16 Jun 2016
    22 Jun 2016
    Link to this post
    Hi everyone,

    Firstly, I want to set gridview (gv) to multi-select and I want to get selected items of gv.
    e.g.:
    I have list of contacts in gridview. How can I add checkbox for each item?
    In javascript, How can I get selected items (get list of contactid of selected items) ?

    Many thanks,
    Quang Anh
  2. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    23 Jun 2016 in reply to quanganh
    Link to this post
    Hello Quang,

    To add a checkbox to each grid item would involve either some custom template work or a new Grid widget all together.

    However the API get the items selected from the grid is fairly simple and already works:

    var grid = $find("C003_ctl00_ctl00_EntityRecordListGrid");
    var items = grid.get_selectedItems();
    for(var i = 0; i < items.length; i++) {
    	var item = items[i];
    	
    	var contactid = item.getDataKeyValue("contactid");
    	// do something with contactid
    }
    

    To allow selection of multiple items you must enable it by modifying the template and setting the AllowMultiRowSelection property on the RadGrid control to "True"

    Regards,
    Clinton
    Last modified on 23 Jun 2016 20:06 by Clinton Bale
  3. quanganh
    quanganh avatar
    33 posts
    Registered:
    16 Jun 2016
    Answered
    23 Jun 2016
    Link to this post
    Hi Clinton,

    Many thanks for your help. Now I use custom template and add telerik:GridClientSelectColumn. It's OOTB.

    Regards,
    Quang Anh
3 posts, 2 answered