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

[Solved] assinging ClientSettings.ClientEvents.OnCommand causes the NoRecordsTemplate to not display

4 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob T
Top achievements
Rank 1
Rob T asked on 17 Nov 2009, 11:27 PM
Hi,

This may sound odd but when I assign a OnCommand handler to a RadGrid, either in the code behind or declaratively, the default no record template is not shown when I bind to an empty data source.  I tried a few other ClientSettings, none of them caused the same issue.

My RadGrid is nothing special. Here is one I can reproduce the issue with.

<rad:RadGrid ID="ReasonsGrid" EnableAjax="true" runat="server" Skin="Default" GridLines="None" 
        AllowAutomaticUpdates="False" AllowMultiRowEdit="False" DataSourceID="ReasonsDataSource"
        <ClientSettings> 
            <ClientEvents OnCommand="Grid_OnCommandHandler" /> 
        </ClientSettings> 
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="Applicationreasonid"
            <Columns> 
                <rad:GridBoundColumn DataField="ReasonTypeString" HeaderText="Type" SortExpression="Type" 
                    UniqueName="Type" Visible="True" ReadOnly="true"
                </rad:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </rad:RadGrid> 


Any Ideas?

4 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 20 Nov 2009, 07:37 AM
Hello Rob,

The reported by you issue is a bug as my colleague Yavor has confirmed in support ticket you posted on the same subject.
As a workaround I suggest that you make the NoRecordsTemplate visible by using the following CSS style:
<style type="text/css">
.rgNoRecords {
    display: block !important
}
</style>

I hope this will help you.

Sincerely yours,
Mira
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
Rob T
Top achievements
Rank 1
answered on 20 Nov 2009, 06:05 PM

While this is an interesting approach it is not a passable workaround.

That style is ignored in FF and in IE it makes the NoRecords template show all the time, regardless of wether or not there are in fact any records.

How far you you think a fix is?  If it's going to be a while I can look into other options.  Please advise.
0
Mira
Telerik team
answered on 25 Nov 2009, 03:37 PM
Hi Rob,

I am attaching a sample project I made for you in which the style I suggested before is set only when needed:
if (RadGrid1.MasterTableView.Items.Count == 0)
            Response.Write("<style type=\"text/css\"> .rgNoRecords { display: block !important } </style>");

It is working fine on my side under FF and IE on my side.

Please take a look at it and tell me if there are any differences on your end.

All the best,
Mira
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
Dean Wyant
Top achievements
Rank 1
answered on 14 Dec 2009, 05:59 PM

Assigning a handler to OnCommand puts the grid into "client-side data binding" mode. In this mode, the grid is rendered with the NoRecordsTemplate hidden (display: none) and sortable headers are rendered with hidden asc and desc input elements. When performing client-side data binding, the client script should unhide the NoRecordsTemplate when appropriate and handle the hiding/showing of the sort icons as needed. I am not completely familiar with all of the necessary actions needed in the script for client-side data binding. There is some help at:
Client-side binding

If you have OnCommand set to a handler and you are not performing client-side binding, you can keep the grid in "server-side binding" mode by assigning the handler in javascript and leaving OnCommand unassigned.

Every control gets created with methods for adding events. The methods are named "add_[event]" where [event] equals the event name without the "On" and with a lowercase first letter.

Example:

C# (or use the property in aspx)  
ClientSettings.ClientEvents.OnGridCreated = "onGridCreated"
function onGridCreated(sender, args)  
{   
  sender.add_command(onGridCommand);  
}  
 
function onGridCommand(sender, args)  
{  
  // do your thing  
}  
 
 

When using server-side binding, hooking OnCommand like this makes the NoRecordsTemplate display properly and gets rid of the extra sort input elements in the headers (as well as other things).

Dean

Tags
Grid
Asked by
Rob T
Top achievements
Rank 1
Answers by
Mira
Telerik team
Rob T
Top achievements
Rank 1
Dean Wyant
Top achievements
Rank 1
Share this question
or