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

Manually load data into grid with custom transport function and server paging/sorting/filtering

2 Answers 281 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stacy
Top achievements
Rank 2
Stacy asked on 17 Jul 2013, 07:46 PM
I have a grid that I have hooked up to a PHP webservice. The dataSource.transport.read option is set to the following:

function(operation)
{
    if($('#grid').data('bindData') !== false)
    {
        var params = operation.data;
        params['id'] = $('#grid').data('webServiceId');
        $.ajax({
            url: 'webservice.php',
            contentType: 'application/json',
            type: 'POST',
            data: kendo.stringify(params),
            success: function(response) { operation.success(response); }
        });
    }
}


The bindData is just a boolean condition I'm setting so that it won't make requests to the webservice at certain points.

This works for normal functionality. The issue here is that I'm dynamically setting the pageSize option based on how much available vertical space is in the content area of the grid. So when I initialize it, I don't want to make a webservice request right away, so I set the option to false, calculate the space, set the pageSize, then want to make the call to run the transport function, but not sure how to do this properly. I can call it manually using $('#grid').data('kendoGrid').dataSource.transport.read(); but that doesn't send the parameters to it so the 'operation' parameter is undefined and the webservice doesn't get any of the paging, sorting or filtering options. And calling dataSource.read() or refresh() doesn't seem to work either.

How can I accomplish this? Is there a way to pass the transport function the necessary parameters or is there a better way to handle it?

Let me know if there's anything else you need.

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 19 Jul 2013, 02:50 PM
Hi Stacy,

 
From the provided information it seems that you are using custom ajax transport to bind the grid - please note that current scenario is out-of-scope of our support service, however if you provide runable sample (you can use jsBin for example) I will try to suggest a better solution that will work for you. 

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
Stacy
Top achievements
Rank 2
answered on 08 Aug 2013, 09:58 PM
I did not have a chance to set up a runable sample for this at the time, but what I ended up doing to get it to work is the following: 

function(operation)
{
    if($('#grid').data('bindData') !== false)
    {
        var params = operation.data;
        params['id'] = $('#grid').data('webServiceId');
        $.ajax({
            url: 'webservice.php',
            contentType: 'application/json',
            type: 'POST',
            cache: false,
            data: kendo.stringify(params),
            success: function(response) { operation.success(response); }
        });
    }
    else
    {
        var params = operation.data;
        $.ajax({
            cache: false,
            success: function(response) { operation.success(response); }
        });
    }
}
I included the 'else' as it seems it needs at least an empty response on the initial bind, then it will function normally and the dataSource.read() function will trigger the transport properly.
Tags
Grid
Asked by
Stacy
Top achievements
Rank 2
Answers by
Vladimir Iliev
Telerik team
Stacy
Top achievements
Rank 2
Share this question
or