Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / How do I get the data from the row selector?

How do I get the data from the row selector?

New Discussion
Ryan Coleman
Ryan Coleman asked on Mar 24, 2015 4:19 PM

Guys,

I am working with an igGrid in jQuery and I am trying to figure out how to get the data from the row that is being selected with the row selector.

Here is my code below for the example table. As I said, I am just trying to figure out how to get the fields from the row that was selected and then use them in another jquery function.

function createCboxSelectorsGrid() {
    $("#cbRowSelectors").igGrid({
        width: "100%",
        autoGenerateColumns: false,
        dataSource: northwindEmployees,
        responseDataKey: "results",
        dataSourceType: "json",

        columns: [
            {
                headerText: "Employee ID",
                key: "ID",
                dataType: "number",
                width: "120px"
            },
            {
                headerText: "Name",
                key: "Name",
                dataType: "string"
            },
            {
                headerText: "Title",
                key: "Title",
                dataType: "string"
            },
            {
                headerText: "Phone",
                key: "Phone",
                dataType: "string"
            }
        ],

        features: [
            {
                name: "Responsive",
                enableVerticalRendering: false,
                columnSettings: [
                    {
                        columnKey: "ID",
                        classes: "ui-hidden-phone"
                    }
                ]
            },
            {
                name: "RowSelectors",
                enableCheckBoxes: true,
                enableRowNumbering: false
            },
            {
                name: "Selection"
            }
        ]
    });
}

 

Sign In to post a reply

Replies

  • 0
    Zdravko Kolev
    Zdravko Kolev answered on Jul 21, 2014 7:58 AM

    Hello Ryan,

     Thank you for contacting us.

     I can recommend you two ways to access the selected rows data.

     First is to get it through the API with selectedRow/selectedRows method. This merhod will return an array of selected rows where every object has the format {element(tr), index}

    For more info : https://www.igniteui.com/help/api/2014.1/ui.iggridselection#methods:selectedRows

     Second way is when you get the array from above to use the row object index property which will give you the index of the selected row in the current data view. You can retrieve the data object easily with the following code:

    $('#grid1').data('igGrid').dataSource.dataView()[indx];

     Code snippet:

    Code Snippet
    1. $(function () {
    2.         $("#getThemAllBtn").click(function () {
    3.             var rows = $('#grid1').igGridSelection('selectedRows');
    4.             var ids = [rows.length];
    5.             
    6.  
    7.             for (var i = 0; i < rows.length; i++) {
    8.                 var indx = rows[i].index;
    9.  
    10.                 $('#grid1').data('igGrid').dataSource.dataView()[indx];
    11.  
    12.                 //this will return you object like:
    13.                 //Object { ProductId=4, Name="Jeans", Number=34, more…}
    14.                 ids[i] = rows[i].id;
    15.             }
    16.  
    17.             $("#selectedRowsPKs").val(ids);
    18.         });
    19.     });

     Looking forward to hearing from you.

    • 0
      Ryan Coleman
      Ryan Coleman answered on Jul 22, 2014 8:15 PM

      Thank you for the information. I believe that is exactly what I was looking for.

      • 0
        Zdravko Kolev
        Zdravko Kolev answered on Jul 23, 2014 12:50 PM

        I am glad to hear that.

        Thank you for using our products!

      • 0
        Ryan Coleman
        Ryan Coleman answered on Jul 24, 2014 2:52 AM

        Zdravko,

        I know this is a very late reply but do you guys happen to have a working MVC4 example that I can download that would show the functionality that I am asking about?

      • 0
        Zdravko Kolev
        Zdravko Kolev answered on Jul 24, 2014 11:27 AM

        Hello Ryan,

        No it is not at all, I am attaching you a sample that I hope will be nearest to the functionality that you desire.

        Please note how I fill array (selectedRowsDSobjects) with row objects on button click and later can be passed to the controller.

    • 0
      Thibaud Lescuyer
      Thibaud Lescuyer answered on Mar 16, 2015 3:23 PM

      This approach works for getting the dataset for selected rows however for us this breaks the multiselect feature with checkboxes. The following represents the block of code handling selection for us

      {
          name: "Selection",
          multipleSelection: true,
          activation: true,
          persist: true,
      
          rowSelectionChanged: function (evt, ui) {
      
              scope.selectedIds = ui.selectedRows.map(function (val) {
                  return val.id;
              });
      
              var selectedRow = element.igGrid("selectedRow");
      
              var data = element
                  .data("igGrid")
                  .dataSource
                  .dataView()[selectedRow.index];
      
              scope.$broadcast("selectionChanged", {
                  selectedIds: scope.selectedIds,
                  dataObj: data
              });
          }
      }

       

      As you can probably tell we are using the grid in an angular app. When we do this, we are unable to select multiple rows through checkboxes. However, the CTRL+Click works.

      • 0
        Thibaud Lescuyer
        Thibaud Lescuyer answered on Mar 24, 2015 4:19 PM

        no feedback on this ?? 

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Ryan Coleman
Favorites
0
Replies
7
Created On
Mar 24, 2015
Last Post
10 years, 11 months ago

Suggested Discussions

Created by

Created on

Mar 24, 2015 4:19 PM

Last activity on

Feb 25, 2026 9:11 AM