Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / get the column index from a key name

get the column index from a key name

New Discussion
seang
seang asked on Mar 20, 2013 4:28 PM

Hello Stanislas,

Thank you for posting in our community.

What I can suggest for adding an unbound column in igGrid is adding it in the columns collection as following:

.Columns(col =>{    col.For(c => c.ProductID).HeaderText("ProductID");    .

   .    col.Unbound("Delete").HeaderText("Delete").DataType("string").Template("<input type='button' value='Delete row' onclick='deleteRow(${ProductID})' class='delete-button'/>");})

I believe you will find the following articles in our documentation useful:

I need to get the column index from a key as selectCell requires it but the ui only gives a key name?

columnSorting: function ( evt, ui )
{
_igGridSelection.clearSelection();
var col = ui.owner.grid.columnByText(ui.columnKey);
//how to get the column I'm in?????????????
var colIndex = 1;
for (var i = 0; i < ui.owner.grid.allRows().length; i++)
_igGridSelection.selectCell(i, colIndex);
return false;
}

 

Sign In to post a reply

Replies

  • 0
    Maya Kirova
    Maya Kirova answered on Mar 20, 2013 3:00 PM

    Hello seang,

     

    Thank you for posting in our forum.

     

    To get the index you’ll need to loop through the columns of the igGrid and find the index in which the column with that key is located in the collection. For example:

    var currentRowInd = 0;
    for (var i = 0; i < columns.length; i++) {
      if (columns[i].key == ui.columnKey) {
          currentRowInd = i;
      }
    }

    Let me know if you have any questions or concerns.

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://www.infragistics.com/support

     

    • 0
      seang
      seang answered on Mar 20, 2013 3:42 PM

      I tried that approach but I never could find the total columns, nor a member that gave me an array of columns? Also are column keys unique? For example can two columns have the same name. Or is it considered best to keep a unique key but change the column text?

      key  1,2,3,4

      text  a,a,a,a

      this maybe clear it all up if my thinking is right.

      • 0
        Maya Kirova
        Maya Kirova answered on Mar 20, 2013 4:26 PM

        Hello seang,

         

        The Key has to be unique. The text can be duplicated .

        It seems that when pasting the code snippet I missed one line:

            var columns = $("#grid").igGrid("option", "columns");

         

        This will return an array of the columns in the grid. You can use it to loop trough the columns.

         

        Let me know if you have any questions or concerns.

         

        Best Regards,

        Maya Kirova

        Developer Support Engineer II

        Infragistics, Inc.

        http://www.infragistics.com/support

         

      • 0
        seang
        seang answered on Mar 20, 2013 4:28 PM
        var columns = $("#grid").igGrid("option", "columns");

         

        thx you!

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
seang
Favorites
0
Replies
4
Created On
Mar 20, 2013
Last Post
13 years, 5 months ago

Suggested Discussions

Created by

Created on

Mar 20, 2013 4:28 PM

Last activity on

Feb 24, 2026 8:00 AM