Telerik MVC Ajax Grid won't expand on save

I have a problem using Telerik MVC network control. I want the control to expand the newly saved row (which is always on top because the rows are sorted in time) when the new row is saved.

In my grid, I used the following code:

@(Html.Telerik()
  .Grid<Models.ViewModels.BestellingModel>()
  .Name("...")
  .DetailView(
       ...
  )
  .DataBinding(
      db =>
          {
              db.Ajax().Select(...);
              db.Ajax().Update(...);
              db.Ajax().Insert(...);
              db.Ajax().Delete(...);
          }
  )
  .DataKeys(
      ...
  )
  .ToolBar(
      ...
  )
  .ClientEvents(e =>
                    {
                        e.OnError("onErrorGrid");
                        e.OnSave("onSaveBestelling");
                        e.OnDataBound("bestellingenVanKlant_onRowDataBound");
                    }
  )
)

      

and here is the javascript:

var isSaved = false;

function onSaveBestelling(e) {
    isSaved = true;
}

function bestellingenVanKlant_onRowDataBound(e) {
    if (isSaved) {
        var grid = $(this).data('tGrid');
        grid.expandRow(0);

        isSaved = false;
    }     
}

      

When I trace the path of the code with firebug, it shows that the code is running. However, in my opinion, the row doesn't expand after inserting a new row.

Any thoughts?

+3


source to share


1 answer


I think you should change your bestellingenVanKlant_onRowDataBound function:

var grid = $(this).data('tGrid');
expandFirstRow(grid, e.row);

      



and use the expandFirstRow function:

function expandFirstRow(grid, row) {
    if (grid.$rows().index(row) == 0) {
        grid.expandRow(row);
    }
}

      

0


source







All Articles