This is a migrated thread and some comments may be shown as answers.

DataSource external filter

2 Answers 294 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
David Blok
Top achievements
Rank 1
David Blok asked on 06 Sep 2016, 07:29 AM

Hi,

I'm trying to reuse the same data from the datasource in on 3 different places on the webpage without recalling the web api.

I'm trying to get this piece of code to work, but without success.
Anyone sees what i'm doing wrong here?

 

I'm trying to add a filter where i a column should equal a value.

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: "/api/articles/getProductSpecifications",
            dataType: "json"
        }
    }
});
 
var filters = dataSource.filter().filters;
 
var new_filter = { field: "groupId", operator: "eq", value: 0 };
filters.push(new_filter);
 
$("#technicalspecs").kendoListView({
    dataSource: dataSource.filter(filters),
    template: kendo.template($("#template").html())
});

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Topalov
Telerik team
answered on 07 Sep 2016, 12:49 PM
Hello David,

The dataSource.filter() method returns undefined, when used as a setter. The dataSource.filter configuration option should be used instead to initially filter a given dataSource.

Please mind that using the same dataSource instance for several dataBound widgets is not recommended, as data operations over the dataSource will be reflected in all widgets, even if  they are made after the widgets have been initialized e.g.:

http://dojo.telerik.com/eLOmo

The suggested approach is to use a separate dataSource instance for each widget, and provide a different filter configuration as necessary, or to store all data items from the initial, unfiltered dataSource, in an array, and then create as many different subsets of items, as necessary, via filtering this array with JavaScript (e.g. the Array.prototype.filter() method), and pass the resulting arrays as a dataSource for the respective different ListViews.

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
0
David Blok
Top achievements
Rank 1
answered on 08 Sep 2016, 11:31 AM

Hi, Thanks for the advice.

I'll setup seperate datasources for each widget.

My idea was to only call the API once, instead of multiple times.

Tags
Data Source
Asked by
David Blok
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
David Blok
Top achievements
Rank 1
Share this question
or