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

Shared remote DataSource with different filters in Grid

7 Answers 456 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Frik
Top achievements
Rank 1
Frik asked on 10 Feb 2012, 04:04 PM
Hi,

I need to bind to a remote json DataSource that is used by 2 Grids.  Easy enough.

However, I need a different filter of the same data for each Grid.  What is the best way to accomplish this without loading the data twice from the remote server?

Thanks!

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Feb 2012, 04:20 PM
Hello,

 This is not possible with a single data source. Filtering it would rebind both grids. You need two datasources. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Frik
Top achievements
Rank 1
answered on 10 Feb 2012, 05:36 PM
1.  How do I create a duplicate of a datasource without reloading it from the server so that I can apply a different filter to it?

2.  Can you please add this as a feature request?  Or add a proxy to a datasource that will allow us to do that.
0
Atanas Korchev
Telerik team
answered on 10 Feb 2012, 05:43 PM
Hi,

You cannot have two remote data sources without making two requests for the data. At least one of the data sources should not be remote (you can use the data of the other data source to feed it).


Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Frik
Top achievements
Rank 1
answered on 10 Feb 2012, 07:54 PM
That is my question... how do I use a local datasource and feed it a copy of the data from the remote data source?
0
Atanas Korchev
Telerik team
answered on 13 Feb 2012, 08:37 AM
Hi,

 Something like this should work:

remoteDataSource.change(function() {
        localDataSource.data(this.data());
});

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jacques
Top achievements
Rank 1
answered on 18 Feb 2013, 09:05 PM
The last solution posted is working, thank you!

However, what bothers me is that the remoteDataSource must know about the local dataSources. Is there any way to bind the localDataSource to the remoteDataSource while defining the localDataSource?

Something like:

$("#dropDownAdrResVille").kendoComboBox({
        dataTextField: "Nom",
        dataValueField: "ID",
        dataSource: new kendo.data.DataSource({ data: Common.villesDataSource.data() }),
        change: function() {
            Representant.ViewModel.representant.AdresseResidentielle.VilleID = this.value();
        }
    }).data("kendoComboBox");

?
0
Atanas Korchev
Telerik team
answered on 19 Feb 2013, 07:52 AM
Hi,

 Your code will work only if the vilesDataSource is already populated at the time the combobox is created. Otherwise data() will return empty array. If this is not the case use my previous suggestion.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Mark
Top achievements
Rank 1
commented on 16 May 2023, 08:27 PM

not sure if anyone cares, but this works now....

Calling datasource.read()...then in the "complete" event in the transport, read: json.....



 complete: function (xhr) {
                   
                    const data = xhr.responseJSON;
                   
                    let gridCOBRA = $('#grid_COBRA').data('kendoGrid');
                   
                    let gridDependents = $('#grid_Dependents').data('kendoGrid');
                   
                    var cobraDS = data.filter(c => c.code == "CP");

                    gridCOBRA.setDataSource(cobraDS);
                    gridCOBRA.refresh();
                   
                    var dependDS = data.filter(c => c.code == "DP");
                    gridDependents.setDataSource(dependDS);
                    gridDependents.refresh();
                }
            },
Nikolay
Telerik team
commented on 19 May 2023, 11:15 AM

Hi Mark,

Thank you for sharing this with the community.

I am sure it will be helpful to others facing the same scenario.

Regards,

Nikolay

Tags
Data Source
Asked by
Frik
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Frik
Top achievements
Rank 1
Jacques
Top achievements
Rank 1
Share this question
or