Hi
I have a kendo grid with sorting enabled. I am trying to sort on a column with a field called "Document_Category"
In the model Document_Category is an object that is comprised of 2 properties: Document_Category_Name (string) and Document_Category_ID (int). I have this field setup as an object this way so I can bind the id to the selected item of a dropdown list in the editor template
How can I can I configure the grid to sort this column by the Document_Category_Name property of the object that the field is bound to.
Is this possible? If not is there another way to bind to a dropdown list?
My code is below; thanks
$("#grid").kendoGrid({
columns: [
{ title: " ", template: "#= doclink(data) #", width: 31 },
{ field: "Document_Category", title: "Category", width: "150px", editor: categoryDropDownEditor, template: "#=Document_Category.Document_Category_Name#" },
{ field: "DOCUMENT_TITLE", title: "Title" },
{ field: "DOCUMENT_FILE_NAME", title: "File Name" },
{ field: "DOCUMENT_DESCRIPTION", title: "Description" },
{ field: "DOCUMENT_FILE_SIZE", title: "File Size" },
{ field: "tags", title: "Tags" },
{ field: "DOCUMENT_CREATION_DATE", title: "Creation Date", format: "{0:dd-MMM-yyyy}" },
{ command: "destroy", title: "Delete", width: "110px" }
],
pageable: {
info: true
}, // enable paging
filterable: false, // enable filtering
sortable: true, // enable sorting
editable: true, // enable editing
toolbar: ["save", "cancel"], // specify toolbar commands
dataSource: {
serverPaging: false,
serverSorting: false,
serverFiltering: false,
pageSize: 5,
schema: {
data: "Data",
total: function (res) {
return res.total;
},
model: {
id: "DOCUMENT_ID",
fields: {
DOCUMENT_ID: { editable: false },
Document_Category: { editable: true },
DOCUMENT_TITLE: { type: "string" },
DOCUMENT_DESCRIPTION: { type: "string" },
tags: { type: "string" },
DOCUMENT_FILE_NAME: { type: "string", editable: false },
DOCUMENT_FILE_SIZE: { type: "string", editable: false },
DOCUMENT_CREATION_DATE: { type: "date", editable: false }
}
}
},
// pageable: true,
batch: true,
transport: {
read: {
url: "GetDocuments?category_id=-1",
contentType: "application/json; charset=utf-8",
type: "POST"
},
update: {
url: "Update", service.
contentType: "application/json; charset=utf-8",
type: "POST"
},
destroy: {
url: "Destroy",
contentType: "application/json; charset=utf-8",
type: "POST"
},
parameterMap: function (data, operation) {
if (data.models) {
return JSON.stringify({ documents: data.models });
} else if (operation == "read") {
//Page methods always need values for their parameters
data = $.extend({ sort: null, filter: null }, data);
return JSON.stringify(data);
}
}
}
}
});
});
function categoryDropDownEditor(container, options) {
$('<input data-text-field="Document_Category_Name" data-value-field="Document_Category_ID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: category_items // array of document categories
});
}