Can someone please provide me with a sample demonstrating how to bind to a WebDataGrid client side NOT using a datasource like in the samples browser? I would like to make a web service call using JSON and bind the data client side, but the only example I can find is the one in the samples browser connecting to a database.
Hello bpg730,
If you use 10.3 version of the toolset there are sample showing this. But keep in mind that this feature is still CTP:
Client side binding
Hope this helps
I have been looking at this example, but it appears as though it is calling methods not available in 10.3. Specifically, I am getting an error on the grid._applyClientBinding() line. Is there an updated version or hotfix that has these methods for the WebDataGrid?
Thank you for the step-by-step response. However, when I try enabling client binding, I get an error saying that I am missing
Infragistics.Web.UI.GridControls.WebDataGrid.js_obf.igWebDataGridClientBinding.js
I then tried the code with that commented it out and it runs through the code successfully but does not display anything in the grid.
NOTE: Since your solution required the grid's _applyClientBinding() function that is not available in the 10.3 release, I had to grab it off the samples page. The code runs through without error, but I am not sure if there are any other functions that are necessary.
I am a little bit confused about this.
As I am not able to reproduce the issue ,
can you please share the code snippet regarding your sample
in a zipped attachment to the forum thread?
Hope hearing from you.
I managed to get it working. The problem with the methods not being available was because inside of one solution, I had a project with IG version 10.2 and another project with IG version 10.3 and it caused some problem with the GAC. I moved the project to a new solution and it fixed the GAC issue.
I now have it successfully binding to the grid, but it is causing 3 problems with the rendering:
1. It is not putting the scroll bar on the side of the grid when it should.
2. When I attempt to retrieve the number of rows after the client binding, it returns 0.
3. I have the grid bound to a button as in the sample. But whenever I press reload again, it appends the data to what is already in the grid. How do I clear the previous data?
Here is the javascript code for binding the data:
function reloadGrid() {
var grid = $find("<%=WebDataGrid1.ClientID %>");
//Show ajax loading
grid._pi.show(grid);
$.ajax({
url: 'WebServices/GetJSONData.asmx/getIGGridData',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, st) {
if (st == "success") {
var newData = JSON.parse(data.d);
var item;
var dataSource = grid._get_dataSource();
if (!grid.tableTemplate)
grid.tableTemplate = grid._elements.dataTbl.lastChild.cloneNode(true);
for (var i = 0; i < newData.length; i++) {
item = newData[i];
$(grid.tableTemplate).render(item).appendTo(grid._elements.dataTbl.lastChild);
dataSource.push(newData[i]);
}
grid._set_dataSource(dataSource);
grid._applyClientBinding();
//Hide ajax loading
grid._pi.hide(grid);
//numRows always gets set to 0, it should be 200
var numRows = grid.get_rows().get_length();
},
error: function() {
alert("Error with AJAX callback");
});
$(grid._elements.dataTbl.lastChild).empty(); // call that before you load the new data
in fact you don't need to call tmpl() or render for every record, it should work fine if you pass the whole array, too:
$(grid.tableTemplate).render(newData).appendTo(grid._elements.dataTbl.lastChild);
Hope it helps,
Angel
Hi,
I tried $(grid.tableTemplate).render(newData).appendTo(grid._elements.dataTbl.lastChild); but it's throwing an exception. Object doesn't support this property or method. I am using JQuery 1.4.2, so should I be using a more newer version?
Dave
Hello,
I got the load working but the functionality of the grid does not work after pressing load. I am doing just a basic row selection. The hidden columns does not work either.
-------------------------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DonorsLoad.aspx.vb" Inherits="DonorProcessing.DonorsLoad" %>
<%@ Register Assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI" TagPrefix="ig" %><%@ Register Assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Donors</title></head><body><form id="frmInput" method="post" runat="server"><ig:WebScriptManager ID="WebScriptManager" runat="server"></ig:WebScriptManager><ig:WebDataGrid ID="wdgDonors" runat="server" AutoGenerateColumns="False" Height="600px" Width="98%"> <AjaxIndicator BlockArea="Control" RelativeToControl="True" /> <Columns> <ig:BoundDataField DataFieldName="AccountID" Hidden="True" Key="AccountID"> <Header Text="AccountID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="LastName" Key="LastName"> <Header Text="Last Name" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FirstName" Key="FirstName"> <Header Text="First Name" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Address" Key="Address"> <Header Text="Address" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="City" Key="City"> <Header Text="City" /> </ig:BoundDataField> </Columns> <behaviors> <ig:Selection RowSelectType="Single" CellClickAction="Row" Enabled="true" /> </behaviors></ig:WebDataGrid><input type="button" id="btnLoad" class="button" value="Load" /><input type="button" id="btnSelect" class="button" value="Select First Row" /><script type="text/javascript" src="Scripts/jquery-1.4.2.js"></script><script type="text/javascript" src="Scripts/jquery.tmpl.js"></script><script type="text/javascript"> $("#btnLoad").click(function () {
var grdDonors = $find("wdgDonors"); var jsonString = { "Donors": [{ "AccountID": "1", "LastName": "Last Name 1", "FirstName": "First Name 1", "Address": "Address 1", "City": "City 1" }, { "AccountID": "2", "LastName": "Last Name 2", "FirstName": "First Name 2", "Address": "Address 2", "City": "City 2"} ]
};
var dataSource = grdDonors._get_dataSource(); var arr = jsonString.Donors;
if (!grdDonors.tableTemplate) grdDonors.tableTemplate = grdDonors._elements.dataTbl.lastChild.cloneNode(true);
for (var i = 0; i < arr.length; i++) { dataSource.push(jsonString.Donors[i]); }
grdDonors._set_dataSource(dataSource); grdDonors._pi.show(grdDonors); grdDonors._applyClientBinding(); grdDonors._pi.hide(grdDonors); }); $("#btnSelect").click(function () { var grdDonors = $find("wdgDonors"); var selectedRows = grdDonors.get_behaviors().get_selection().get_selectedRows(); selectedRows.add(grdDonors.get_rows().get_row(0)); });</script></form></body></html>
----------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
wdgDonors.EnableClientRendering = True wdgDonors.DefaultColumnWidth = 200
Dim Donors As New List(Of String)
wdgDonors.DataSource = Donors wdgDonors.DataBind()
End Sub
------------------------------------------------------------
Any help is appreciated. I understand it is CTP but I really need to load using ajax/json on client side.
Will
Hey Will,
What version of jQuery are you using? I can't seem to get mine to display the rows, even though I'm doing the exact same thing as you. Well almost. I'm send inding an ID to a WCF Web Service and it's returning a JSON sting. I get those objects out of the string and push them into another array, then use that is my datasource, but still it's empty. I'm using jquery-1.4.2.
Any ideas?
Hello Dave,
Make sure you have the template script also.
<script type="text/javascript" src="Scripts/jquery-1.4.2.js"></script><script type="text/javascript" src="Scripts/jquery.tmpl.js"></script>
it will fail if you do not initialize the template:
I am doing basically the same as you. This was a stripped down version to show the problem. I am returning json from a webmethod and it is working and loading but can not interact with the grid once it is loaded. I just did a local var json to show the problem after load.
<WebMethod(EnableSession:=True)> _<Script.Services.ScriptMethod(ResponseFormat:=Script.Services.ResponseFormat.Json)> _ Public Shared Function DonorsByName(ByVal LastName As String, ByVal FirstName As String)
The concept is awesome
Hi Will,
Thanks for the info but I'm still having issues. I think the problem might be that I'm using 3.5 and not 4.0 like you are. When I call the _applyClientBinding() I get a JavaScript error because the render method is not there so I think there is more to this problem than we know. I tried a few other things and managed to get my rows to show up, but they're all blank. I've spent so much time on this that I can't waste anymore on it which is a real shame because, like you say, it's an awesome concept and lightening fast if it works.
One thing is for sure and that is my WCF code works perfectly as I can see the JSON string coming back from it and all the Objects when it's parsed. It's a real shame that I don't have the time to figure out the Grid rendering. I have to settle for an ugly PostBack.
Time is money and I can't be wasting anymore time...
ThanksDave
It only works (i use that turm loosly) with 4.0. I am in the same boat as you. I can not spend any more time on it because it appears that it is not even close to being anything thing but a demo. I can not hold up my project up waiting on the june release of version 11. I was hoping that just the basic row selection would work because that is all I needed. no editing, just be able to dbl click on a row and I could bring up a property page.
Oh well.
Later,