Reputation: 3023
I'm having a hard time finding out how I can sort columns in a grid thar are set up with the Template property, like below:
@(Html.Kendo().Grid(Model.UnitDetails)
.Name("unitGrid")
.DataSource(ds => ds
.Ajax()
.Read(read => read.Action("Units_Read", "Fleet"))
.AutoSync(true)
.ServerOperation(true)
)
.Columns(columns =>
{
columns.Bound(p => p.ViewUnitContract.CurrentRun.Operation.WellContract.Location).Title("Well Site").Sortable(true);
columns.Bound(p => p.ViewUnitContract.Name).Title("Unit Name").Width(200);
columns.Template(p => { }).ClientTemplate(" ").Title("Well");
columns.Template(p => { }).ClientTemplate(" ").Title("Run").Width(75);
columns.Template(p => { }).ClientTemplate(" ").Title("Task").Width(365);
columns.Template(p => { }).ClientTemplate(" ").Title("Activity").Width(200); ;
columns.Template(p => { }).ClientTemplate(" ").Title("Depth (m)").Width(115);
columns.Template(p => { }).ClientTemplate(" ").Title("Speed (m/min)").Width(90);
columns.Template(p => { }).ClientTemplate(" ").Title("Weight (kg)").Width(90);
})
.ClientRowTemplate(Html.Partial("_ClientRowTemplate", Model).ToHtmlString())
.Sortable())
Sorting the two first columns works just fine, but is it possible to sort the ones bound with ClientTemplates?
Upvotes: 3
Views: 6140
Reputation: 4054
To sort a column, it must be a Bound column. You could still set the ClientTemplate
on the Bound
column, but the Template
alone will not be sortable.
One workaround is to update your view model to have whatever "calculated" value (using that term loosely) calculated on the controller and then returned through to the view. In that case, you could use Bound columns.
Upvotes: 7