Reputation: 3744
this should be a simple one, but i cannot find anything which is getting annoying, has anyone else had luck with this one...
i am adding item to kendo datasource that is bound to a grid. is there a way i can resort the grid??
$("#grid").data("kendoGrid").dataSource.add(data);
$("#grid").data("kendoGrid").dataSource.sort();
or when i cann the
$("#grid").data("kendoGrid").refresh();
this should sort it
really can't get anything to work, i'd like to be able to dynamically add records to grid, and have the grid resort.
this is how i am defining my grid in my cshtml page
@(Html.Kendo().Grid(Model.List)
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Width(100);
columns.Bound(p => p.Age).Width(100);
columns.Bound(p => p.Name).Width(100);
})
.Events(events => events.Change("onChange").DataBound("onDataBound"))
.DataSource(dataSource => dataSource
.Ajax()
.Model(m => m.Id(g => g.Gid))
.Read(read => read.Action("GetName", "NamesController", new { Id = Model.Id }).Type(HttpVerbs.Get))
.Sort(sort => {
sort.Add(p => p.Id);
sort.Add(p => p.Age);
sort.Add(p => p.Name);
})
)
Upvotes: 0
Views: 1147
Reputation: 3744
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
)
basically setting .ServerOperation(false) fix this. this will enable client side sorting
Upvotes: 0
Reputation: 40917
Datasource has a sort
method (documentation here). Basically you need to fix the sort criteria and then invoke this method.
Example:
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
]
});
dataSource.sort({ field: "age", dir: "desc" });
Upvotes: 1