Fungsi parameter map pada Kendo Grid bermanfaat untuk filter / sort foreign key.
[code language=”javascript”]
var dataSource = new kendo.data.DataSource(
{
transport: {
read: {
url: "@Url.Action("Binding")",
dataType: "json",
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
} else {
if (options.filter) {
filter = options.filter.filters;
for (var i in filter) {
if (filter[i].field == "CreateDate") {
var date = filter[i].value;
filter[i].value = kendo.toString(date, "yyyy-MM-dd");
} else if (filter[i].field == "Status") {
} else if (filter[i].field == "Name") {
filter[i].field = "contractor.first_name";
var sor = { field: "contractor.last_name", operator: ‘contains’, value: filter[i].value };
filter.push(sor);
options.filter.logic = "or";
} else if (filter[i].field == "Position") {
filter[i].field = "doc_position.id";
} else if (filter[i].field == "Company") {
filter[i].field = "contractor.company.name";
} else if (filter[i].field == "DurationContract") {
var date = new Date(filter[i].value);
filter[i].field = "start_date";
filter[i].operator = "lte";
filter[i].value = kendo.toString(date, "MM/dd/yyyy");
var fil = { field: "end_date", operator: "gte", value: filter[i].value };
filter.push(fil);
}
}
}
if (options.sort) {
sort = options.sort;
for (var i in sort) {
if (sort[i].field == "ContractSpv") {
sort[i].field = "contract_supervisor";
} else if (sort[i].field == "Name") {
sort[i].field = "contractor.first_name";
var sor = { field: "contractor.last_name", dir: sort[i].dir };
sort.push(sor);
} else if (sort[i].field == "Position") {
sort[i].field = "doc_position.position";
} else if (sort[i].field == "Company") {
sort[i].field = "contractor.company.name";
} else if (sort[i].field == "DurationContract") {
sort[i].field = "start_date";
var sor = { field: "end_date", dir: sort[i].dir };
sort.push(sor);
}
}
}
console.log(options);
return options;
}
},
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
});
[/code]