This is a migrated thread and some comments may be shown as answers.

[Solved] Select inserted row after save (with popup edit)

1 Answer 583 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wim
Top achievements
Rank 1
Wim asked on 24 Oct 2014, 01:45 PM
Is there any way to select the inserted row after saving a popup edit?

This is my grid:
01.@(Html.Kendo().Grid<Receipt>()
02.    .Name("GridReceipts")
03.    .Columns(columns => {
04.        columns.Bound(o => o.ReceiptId);
05.        columns.Bound(o => o.Status);
06.        columns.Command(c => {
07.            c.Edit().Text(" ");
08.            c.Destroy().Text(" ");
09.        });
10.    })
11.    .DataSource(d => d
12.        .WebApi()
13.        .Model(m => {
14.            m.Id(o => o.ReceiptId);
15.        })
16.        .Create(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Receipts" })))
17.        .Read(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Receipts" })))
18.        .Update(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Receipts", id = "{0}" })))
19.        .Destroy(c => c.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "Receipts", id = "{0}" })))
20.    )
21.    .Pageable(p => p
22.        .Refresh(true)
23.        .PageSizes(true)
24.        .ButtonCount(5)
25.    )
26.    .ToolBar(toolbar => toolbar.Create())
27.    .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("Receipt"))
28.    .Sortable(s => s.AllowUnsort(true))
29.    .Selectable()
30.    .Deferred()
31.)

I have tried the following, which selects the row but immediately deselects it (as if the grid refreshes?):
1.function saveReceipts(e) {
2.    var grid = $("#GridReceipts").data("kendoGrid");
3.    var dataItem = grid.dataSource.get(e.model.ReceiptId);
4.    var row = grid.tbody.find("tr[data-uid='" + dataItem.uid + "']");
5. 
6.    grid.select(row);
7.}

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Oct 2014, 12:42 PM
Hello,

You should wait for the grid to be rebound after the changes are synchronized in order to avoid losing the selection. The dataBound event can be used for this purpose e.g.
function saveReceipts(e) {
    this.one("dataBound", function () {               
        this.select(this.tbody.children("[data-uid='" + e.model.uid + "']"));
    });
}


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Wim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or