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

Initial load locally with remote datasource

5 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 13 Jul 2013, 03:53 PM
I have a scenario where I would like to load the data for the Grid locally on the first page load, and then have the Grid use a remote datasource for any subsequent paging.

Take search for example. A user enters search parameters that are POSTed to the server, which then finds results and displays them in a grid on a page. Since I have those first set of results on the server when I'm rendering the page the first time, I want to load the Grid with them. But, then I want to use ajax for any paging beyond that first set.

What's the best way to do that?

5 Answers, 1 is accepted

Sort by
0
Josh
Top achievements
Rank 1
answered on 14 Jul 2013, 03:49 AM
I actually have an approach that is working for me. However, I would still love to know if there is a better (or more Kendo'ish) way to do this:

// somewhere at a scope the datasource can access set the variable:
var bFirstRun = true;
 
// in the datasource, set:
transport: {
                    read: function(options) {
                        console.log(options);
                        if (bFirstRun)
                        {
                            options.success({
                                rows: {{ rows|to_json }},
                                totalRows: {{ totalRows }}
                            });
                            bFirstRun = false;
                        }
                        else
                        {
                            $.post("{% url 'search_url' %}", $.param(options.data) + $("#search-form").serialize())
                                    .done(function ( data ) {
                                        console.log("Returned post data:", data);
                                        options.success(data);
                                    })
                                    .fail(function ( data ) {
                                        console.log("Post failed:", data);
                                        options.error(data);
                                    });
                        }
                    }
                }
0
Accepted
Alexander Valchev
Telerik team
answered on 17 Jul 2013, 07:06 AM
Hi Joshua,

Thank you for getting in touch with us.
The DataSource does not provide a build-in mixed (local and remote) transport. The only suitable way to achieve that is by implementing custom read transport function like in your code snippet.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Josh
Top achievements
Rank 1
answered on 16 Feb 2015, 04:13 PM
Is this supported now?  Can the example provided be adapted to work with paging?
0
Josh
Top achievements
Rank 1
answered on 16 Feb 2015, 05:02 PM
Josh - the example I provided has been working fine for us and supports paging.

I've not seen any change on the Telerik side to enable this in any built-in way, and I wouldn't expect it... but, they can of course reply with any further details. ;)
0
Alexander Valchev
Telerik team
answered on 17 Feb 2015, 11:41 AM
Hello guys,

Josh, I can confirm that there is still no build-in way provide a build-in mixed (local and remote) transport.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Josh
Top achievements
Rank 1
Alexander Valchev
Telerik team
Josh
Top achievements
Rank 1
Share this question
or