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

[Solved] Client Side DataBind with No Records

3 Answers 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick Hampton
Top achievements
Rank 1
Patrick Hampton asked on 15 Sep 2009, 11:29 PM
Hello

I have a RadGrid that is bound on the server during the page load, then using page methods and Client Side data binding is updated based on various user actions.  To complicate matters I needed to use Template Columns, so I perform actions on the DataBound event (client and server) that manages the appearance of each row in the Grid.  I have run into a few roadblocks and am hoping that some can help point me in the right direction.

1.  If on the initial load the RadGrad contains data, and I bind it on the client to an empty dataset, the NoRecordsTemplate does not show.  Is there a way to get this to show in this scenario?

2.  If on the initial page load the RadGrid does not contain data I get the NoRecordsTemplate as expected.  However, if I then bind it on the client to a dataset that contains data, I get exceptions because the grid appears to be reusing the row that was created from the NoRecordsTemplate which does not have the same Item templates as a data row.  So in this scenario is it possible to get the DataRow "Template" so to speak from the Grid object on the client so that I can build new data rows when rebinding on the client?

3.  If the intial page load has fewer records the a following client side data bind, then when new rows are created for the additional data items, the rows do not have any controls rendered for cells that are associated with a template column.  So is there a way to get at the item template so that I can build these controls on the client?

Thanks in advance for your help.
Patrick

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 21 Sep 2009, 10:33 AM
Hello Patrick,

Straight to your questions:

1. You can use the following code to have NoRecordsTemplate showing:
 - include the following scripts into your ScriptManager/RadScriptManger:
<asp:ScriptManager ID="RadScriptManager1" runat="server" > 
        <Scripts> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />   
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />   
        </Scripts> 
    </asp:ScriptManager> 

 - and attach handler to client OnCommand event:
 
<ClientSettings> 
  <ClientEvents OnCommand="function(){}" /> 
</ClientSettings> 

2nd and 3rd: When using client-side data-binding RadGrid use the records generated on server for client binding. These items can be created if RadGrid is bound on server, if it is not ClientEvents.OnCommand handler should be provided(as listed above) and RadGrid will bound itself to fake PageSize records.
This records will used to populate the data that is supplied on client-side. If the records on client is more than the records created initially RadGrid will create additional rows. However for this additional rows you will have to manage the content in the cells manually especially for template columns.
This can be achieved by handling OnRowDataBound event.

More details on RadGrid client-side data-binding might be found below:
http://www.telerik.com/help/aspnet-ajax/client-side-binding.html

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Patrick Hampton
Top achievements
Rank 1
answered on 23 Sep 2009, 10:14 PM
Nikolay

I added a handler to the client side OnCommand event in the grid and I can now see the NoReportsTemplate when databinding on the client.  However, that now breaks the NoReportTemplate when I bind on the server.  I can work around it by handling the client side pageLoad as follows, but I'm wondering if there is something I may have missed.

 

 

function pageLoad(sender, eventArgs)  
{  
    var masterTable = $find(reportsGrid).get_masterTableView();  
    if(masterTable.get_dataItems().length == 0)  
    {  
        masterTable.set_dataSource(new Array());  
        masterTable.dataBind();  
    }  

 


Back to my 2nd and 3rd questions again.  I can work around having to populate the cell content on Item Databoud since I already have to do this for the Template columns anyway.  However I have also noticed that if I go from having No Records on the Server DataBind, to having records on the Client Database that all of my new rows are created with the NoRecords row style.  So styles that are normally applied through ItemStyle and AlternatingItemStyle are not applied to new rows in this scenario.  If I start with Records from the Server Data Bind and then Rebind Client Side the row styles are applied as expected.

Patrick
0
Nikolay Rusev
Telerik team
answered on 29 Sep 2009, 07:42 AM
Hello Patrick,

If you do not want to see this initial empty rows you can handle server ItemCreated event and set Display="false" to all GridDataItems. Thus RadGrid will not flicker when you bind it to empty array on client pageLoad event.

Regarding 2-3 question - the extra rows are created with class name rgRow or rgAltRow depending on their index. However ItemStyle will not be applied on the newly created rows, it will be applied only the rows that are build on server initially.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Patrick Hampton
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Patrick Hampton
Top achievements
Rank 1
Share this question
or