Reputation: 150
I have a main view with 3 partial views in. One of the partial views contain a kendo grid which should be sortable.
@(Html.Kendo().Grid(Model)
.Name("tasksgrid")
.Sortable()
.Filterable()
.HtmlAttributes(new { style = "height:100%; font-size:14px;" })
.Columns(columns =>
{
columns.Bound(e => e.Url).Title("URL").Hidden();
columns.Bound(e => e.Id).Title("ID").Hidden();
columns.Template(@<img src="@item.OperatorCreated.ImageSource" style="width:80px;height:80px;"/>).ClientTemplate(" ").Width(100).Title("Picture");
columns.Bound(e => e.Subject).Template(@<div>
<div style="font-size: 20px;">@item.OperatorCreated.Name</div>
<div>@item.Subject<br />@item.Message</div>
</div>).Title("Details").HtmlAttributes(new {id = "detailcolumn"});
columns.Bound(e => e.DateTimeCreated).Title("Date").Width(100).HtmlAttributes(new { id = "datecolumn" });
})
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(p => p.Id))
)
.Events(events => events.Change("onChange"))
.Scrollable()
)
This partial view is only rendered when a certain action in the other view is selected. Which then retrieves data to fill the grid.
function RefreshTasks(name) {
var serviceUrl = "/Tasks/PopulateTasks?actionname=" + name;
var request = $.post(serviceUrl);
request.done(
function (data) {
$("#tasks").html(data);
}
);
}
When sorting is done on the grid the following url is created "localhost:1772/?tasksgrid-sort=DateTimeCreated-desc&tasksgrid-group=&tasksgrid-filter=" which refreshes the whole page meaning my partial view with the grid isn't there anymore.
Is there a way to throw this url into the partial view only.
I found a way to do exactly what I needed for this implementation.
$("#tasksgrid .k-link").click(function (e) {//call the function when column header is clicked
var thelink = e.target.href;//get the url that would be navigated to on sort
var serviceUrl = thelink;
var request = $.post(serviceUrl);//post the url
request.done(
function (data) {
$("#tasks").html(data);//update div
}
);
return false;//cancels navigation
})
Upvotes: 0
Views: 2004
Reputation: 30671
You should configure the grid to use Ajax binding. Otherwise it will refresh the whole page. More info is available in the documentation.
Upvotes: 1