Reputation: 1101
I'm trying to apply custom filter to Kendo DataSource so that it filters using calculation of a few columns. E.g. filter all items that has field1 value greater than filterValue percent of field2 value.
dataSource.filter({
field: 'field1',
operator: function(value) {
return value * 100 / valueFromField2 > filterValue;
},
value: filterValue
})
So basically I need to get an access to other row fields from within a operator function.
Any ideas how to achieve it?
Upvotes: 1
Views: 530
Reputation: 1565
I believe you need to iterate each field value.
Something like:
function (value) {
var rowData = this.dataSource.view();
for (var i = 0; i < rowData.length; i++) { // Iterate each row
$.each(rowData[i].items, function (index, object) { // Iterate each object
var uid = object.uid;
// DO YOUR LOGIC HERE
});
}
}
Upvotes: 0
Reputation: 68
I am not sure how to apply it to your case, but if you want to access other rows in a Kendo Grid, you can:
var grid = $("#grid").data("kendoGrid"); // The complete grid
var row = grid.tbody.find("tr:eq(0)"); // Row index. Starts from 0. Excludes header row
var data = grid.dataItem(row); // 'data' now has all fields for 'row'
Consider an example grid:
column1|column2
---------------
----1--|--One--
----2--|--Two--
---------------
Hence, for eq(0)
:
data.column1: 1
data.column2: One
More information: https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#fields-tbody
Hope this helps :)
Upvotes: 0