Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
265
imp : iterate through grid rows
posted

 I want to interate through the rows of the webgrid and find out if the id of the current
row being added is already there in the grid meaning if that row with that id is already
exists how can this be done on the client side.

Parents
  • 45049
    Verified Answer
    posted

    In the below JavaScript solution, I'm making a number of assumptions:

    • Your grid is a flat (non-hierarchical) grid.
    • I'm using "ID" as the key of the column in your grid that contains the ID.
    • The variable "grid" already contains a reference to your WebGrid.
    • The variable "newId" is the ID of the row you are looking to add.

    var found = false;
    for (var i = 0; i < grid.Rows.length; i++)
    {
        var row = grid.Rows.getRow(i);
        var idCell = row.getCellFromKey("ID");

        if (idCell.getValue() == newId)
            found = true;
    }

Reply Children