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
2732
Selecting a row
posted

Hello,

I'm trying to create a view in MVC using the iggrid 2014.1.2249.
The screen has a grid "preview" of the left side and a detail section on the right side.
It should have the following behaviour:

  • The grid should have paging
  • Selecting a row in the grid populates the detail section
  • The detail section has a save button, pressing it should update the relevant fields in the grid that were changed
  • There is a delete button (outside of the grid), it should remove the selected row
  • There is a new button, it should populate the detail section with a new record
  • Pressing the save button on the "new" detail screen should add the new record to the grid and select the corresponding new row and make sure it's in the "visible" area of the screen/paging

I'm currently stuck on that last part. This is what I have so far.

When clicking on the "save" button of the new screen, I create a form post and my action returns the newly created record (JSON). I add it the datasource but then I don't manage to select the row.

var formData: string = form.serialize();
$.ajax({
type: "POST",
url: form.attr("action"),
data: formData,
success: data => {
   //the new record
   var notification: any = data.notification;
   //primary key of the new record
   var notificationId: any = data.notification.ID;
   //add row
   $('#PreviewGrid').data("igGrid").dataSource.addRow(notification, true);
   //rebind datasource
   $('#PreviewGrid').data("igGrid").dataBind();

   //TODO: select new row
}

I have found that I can select a row using the following:
$("#PreviewGrid").igGridSelection("selectRow", rowindex); 

However, I don't know the row index of the newly created row. I have read that I can find that index number in the following:
$("#PreviewGrid").igGrid("rows")

However, this only contains the rows that are currently visible on the screen (remember: i'm using paging).

So my question is, using paging, how do I find the newly added row, and select it, making it visible on the screen, using the primary key of the added object.

Kind regards,

Michael