Infragistics, Javascript, Jquery

Infragistics igGrid Get Row Data from Javascript

This isn’t well documented (or at  least I had trouble finding the answer to this), so I figured there may be others (or me again down the road) that could use this information.

Essentially I have a grid loaded from a datasource.  I needed to get at the data of a particular row from outside of any grid event, so I had to retrieve the rows from the grid, find the row that I needed and then reference the data.   All in all, once you know the syntax, it’s not that bad.
This line returns an array of the row data:

var dataRow = $("#igDetails").igGrid("dataSourceObject").Records;

Next we want to retrieve a particular row based on a value in a particular column:

var result = $.grep(dataRow, function (e) { return e.Id === id; });

Result will be an array of rows that match your criteria. In our case I just want the first match (ID will be unique, so should be only one row)

Now to retrieve the data:

var description = result[0].Description;

Pretty simple really, but the retrieving the data from the grid took some looking and piecing parts of the documentation together to get what I needed.

.NET, Code, Infragistics, WinGrid

Infragistics WinGrid – Tips and Tricks #1 – Right Click Row Select

I’ve been working with Infragistics tools, specifically the UltraWinGrid for 10 years or more (worked with the Sheridan grid before that, anyone remember those tools?), and outside of the Infragistics forums there seems to be very little in the way of information on this very powerful and complex tool.  Perhaps I can leverage my experiences with these tools into a nice little series of posts on things I’ve discovered over the years.

I came upon a situation where I wanted to right click on a grid, have it select the row under the mouse and bring up a context menu to act on that selected row.  As another requirement I wanted it to only act upon data rows.

I came up with the following extension method.

  1. First get the element under the mouse and determine if it’s a row element.
  2. If it’s a row, is it a datarow?
  3. Make it the active row.
  4. if the row is not already selected, select it and deselect any other row.
  5. if the row is already selected, then do nothing else special with the selection properties.
  6. if we’ve clicked somewhere not a datarow, I clear any selected rows in the grid.
21 public static void RightClickRowSelect(thisUltraGrid grid, Point mouseLocation)  
22 {  
23     UIElement element = grid.DisplayLayout.UIElement.ElementFromPoint(mouseLocation);  
24     var row = element.GetContext(typeof(UltraGridRow)) asUltraGridRow;  
25     if (row != null && row.IsDataRow)  
26     {  
27         grid.ActiveRow = row;  
28         if (!row.Selected)  
29         {  
30            grid.Selected.Rows.Clear();  
31            row.Selected = true;  
32         }  
33     }  
34     else  
35     {   
36        grid.Selected.Rows.Clear();  
37     }  
38  }

Then to use this, I simply call it in the MouseDown event on the grid as follows.

    1     privatevoid grdLabsMouseDown(object sender, MouseEventArgs e)
    2     {
    3       if (e.Button == MouseButtons.Right)
    4       {
    5         grdLabs.RightClickRowSelect(e.Location);
    6       }
    7    }

Pretty basic really, but knowing how to determine what element is under the mouse is a critical tool in your belt when dealing with the WinGrid and opens up the door for a lot of advanced features.