DataSource external filter

3 posts, 1 answers
  1. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 06 Sep Link to this post

    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. Answer
    Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 07 Sep Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
  4. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 08 Sep in reply to Dimiter Topalov Link to this post

    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.

Back to Top