Shaun Rowan
Shaun Rowan

Reputation: 9539

Grouping a grid using knockout-kendo

Using the knockout binding syntax in knockout-kendo, is it possible to define how the data should be grouped? Ideally I'd like to disable the user from grouping and perform the grouping via the binding (or perhaps I will need to create a binding to do this?)

Update:

This seems to work fine if I define my property as a kendo.data.DataSource

var dataSource = new kendo.data.DataSource({
    data: response,
    // group by the "category" field
    group: { field: "category" }
});

Best I can tell, it doesn't appear to me like the knockout-kendo library supplies a hook to feed additional optional parameters to the datasource that it creates for you... So there is no way to supply the "group" modifier to a non-kendo.data.DataSource that you pass in via the simplified, or options syntax.

Upvotes: 1

Views: 1163

Answers (1)

nemesv
nemesv

Reputation: 139748

If you don't want to use a kendo.data.DataSource directly as your data (but in this case I think you should) then one possible (altough kind of hacky) solution is to use the widget option in your binding.

When you are specifing a widget observable property KO-Kendo will set its value with the created Kendo widget.

<div data-bind="kendoGrid: { data: items, widget: widget }"> </div>

Then you can subscribe on the widget change event and set the grouping on the datasource:

this.widget = ko.observable();

this.widget.subscribe(function (value) {
   value.dataSource.group({ field: 'category' });
});

Demo JSFiddle.

Upvotes: 3

Related Questions