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

Disable RadGrid Databinding

2 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gioce90
Top achievements
Rank 1
Gioce90 asked on 15 Jun 2016, 03:12 PM

Hi, I have a problem with my grid. This grid is showed to the user, in a popup, when he click on a link.

 

This is my grid:

<div id="dialog" >
    <telerik:RadGrid ID="RadGrid1" RenderMode="Lightweight"
        ClientDataSourceID="RadClientDataSource1"
        AllowPaging="false" AllowSorting="false" AllowFilteringByColumn="false"
        PageSize="5" runat="server" >
        <MasterTableView DataKeyNames="Name" ClientDataKeyNames="Name" >
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        </ClientSettings>--%>
    </telerik:RadGrid>
</div>

 

and this is my RadClientDataSource:

 

<telerik:RadClientDataSource ID="RadClientDataSource1" runat="server" >
    <ClientEvents OnCustomParameter="ParameterMap" OnDataParse="Parse" />
    <DataSource>
        <WebServiceDataSourceSettings BaseUrl="../ReportService.svc/">
            <Select Url="GetFlusso" DataType="JSON" RequestType="Post" ContentType="application/json; charset=utf-8"
                EnableCaching="false" />
        </WebServiceDataSourceSettings>
    </DataSource>
    <Schema ResponseType="JSON" >
        <Model>
            <telerik:ClientDataSourceModelField FieldName="Name" DataType="String" />
        </Model>
    </Schema>
</telerik:RadClientDataSource>

 

This is my link (created with javascript):

"<a href='javascript: openScartiDialog(" + id + ");'><em>CLICK</em></a>"

where id is a parameter for a select method on web service.

 

Now, these are the functions that parse to/from my web service:

function ParameterMap(sender, args) {
    if (args.get_type() == "read" && args.get_data()) {
 
        var dialog = $("#dialog");
        var id = dialog.id;
 
        if (id != undefined) {
            var request = {
                InputContract: {
                    IdFlusso: id
                }
            };
            args.set_parameterFormat(kendo.stringify(request));
        }
    } else {}
}
 
function Parse(sender, args) {
    var response = args.get_response().Output;
    if (response) {
        if (response.length > 0) {
            args.set_parsedData(response);
        } else {
            var model = [];
        }
    }
}

 

All works. My Web Service works (I have tried with other grids).

The problem is: the request on the server (performed by the RadClientDataSource, called by the RadGrid) is made on page load.

I want to avoid this, I just want that the grid is loaded, showed on the link click (indeed, I want to pass the id parameter). But I don't know how.

 

To be more clear, this is the rest of my implementation: the js code for showing/hiding the popup and for set the id.

 

$(function () {
    $("#dialog").dialog({ autoOpen: false, modal: true, show: "blind", hide: "blind", width: "auto",
        buttons: {
            "OK": function () {
                $(this).dialog("close");
            },
            "Annulla": function () {
                $(this).dialog("close");
            }
        }
    });
 
 
});
 
 
function openScartiDialog(id) {
    var div = $("#dialog");
    div.attr('id', id);
    div.dialog("open");
 
    var grid = $telerik.findGrid("RadGrid1");
    var m = grid.get_masterTableView();
     
    m.rebind();
 
    return false;
}

 

 

2 Answers, 1 is accepted

Sort by
0
Gioce90
Top achievements
Rank 1
answered on 16 Jun 2016, 09:08 AM

Reading your forum I found this tip:
set the grid attribute Visible = "false" . It seemed to work, in fact, the request to the Web service was not made at page load..

But then I noticed that the grid is not created, in fact the methods $find or $telerik.findGrid not work. Can you tell me please how to work around this problem?

0
Viktor Tachev
Telerik team
answered on 20 Jun 2016, 09:05 AM
Hello,

If you set the Visible property on the server you would need to perform postback to change it.

Another approach you can try is to handle the OnCommand event of the RadClientDataSource and cancel it initially. Also, you can add a global variable that will be set after clicking on the button. You can use that variable as flag that will indicate when the data should be requested.

Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Gioce90
Top achievements
Rank 1
Answers by
Gioce90
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or