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

[Solved] EnableNoRecordsTemplate having no effect

7 Answers 528 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 02 Aug 2009, 08:15 PM
I'm having trouble with getting the 'no records' message/template working correctly.

My particular issue is that the NoRecordsTemplate is not being shown when there are no records and the initial data binding takes place on the server side. When the grid is rebound on the client side, then no record message is shown correctly.

In trying to determine why, I created a small test project and found I had the opposite problem. I could not get the no records message to NOT show. I'm hoping that in finding out why I cannot hide the message, I will find out why I can not get it to show in my main project.

Setting the EnableNoRecordsTemplate to false does not hide the message, regardless of whether the <NoRecordsTemplate> element is there.

I cannot find anything in the documentation to suggest why the EnableNoRecordsTemplate has no effect.

Here is my simple grid;

        <telerik:RadGrid ID="RadGrid1" runat="server"
            <MasterTableView EnableNoRecordsTemplate="false"
                <Columns> 
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" /> 
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" /> 
                    <telerik:GridBoundColumn DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" /> 
                </Columns> 
                <NoRecordsTemplate> 
                    <div> 
                        No records custom message.</div> 
                </NoRecordsTemplate> 
            </MasterTableView> 
        </telerik:RadGrid> 

Here is the only code behind used;

    Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Init 
        RadGrid1.DataSource = New Object() {} 
        RadGrid1.DataBind() 
    End Sub 

I have tried the latest internal build, but with the same results.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2009, 06:43 AM
Hello Alex,

You can either set the NoMaterRecordsText property of the MasterTableView  to true or false rather than using the NoRecordsTemplate.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server"
         <MasterTableView NoMasterRecordsText=""
               ......... 

Thanks
Princy.
0
Alex
Top achievements
Rank 1
answered on 03 Aug 2009, 08:05 AM
Hi Princy,

I'm not sure what you mean by setting NoMaterRecordsText to 'true' or 'false' as this is a text property and not a boolean one.

Regardless, the problem still exists regardless of whether I use this property or the no-record template.

I have worked around this issue in the meantime (code below) but I'd still like to know the cause of the problem.

In the grid prerender;
    If RadGrid1.Items.Count = 0 AndAlso RadGrid1.MasterTableView.EnableNoRecordsTemplate Then 
        '... get no records item 
        itemNoRecords.Attributes.Add("style""display: block"
 
    Else 
        '... get no records item 
        itemNoRecords.Attributes.Add("style""display: none"
    End If 

0
Ryan
Top achievements
Rank 1
answered on 01 Sep 2009, 01:11 PM
I am experiencing the same issue.  I've narrowed it down to using the .ClientSettings.ClientEvents.OnCommand call.  I'm not using a NoRecordsTemplate, but am simply setting the .MasterTableView.NoMasterRecordsText.  If I do not use the OnCommand call (comment it out) my NoMasterRecordsText shows up when no records are loaded, otherwise the NoMasterRecordsText does not display.

Client-Side:

 

 

        <telerik:RadGrid ID="TasksGrid" runat="server">  
            <MasterTableView> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="GoTo" HeaderText="Go To" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="50" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50" AllowSorting="false" AllowFiltering="false"></telerik:GridBoundColumn>   
                    <telerik:GridBoundColumn DataField="Edit" HeaderText="History" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="50" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50" AllowSorting="false" AllowFiltering="false"></telerik:GridBoundColumn>   
                    <telerik:GridBoundColumn DataField="Attachment" HeaderText="" SortExpression="Attachment" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="20" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20" AllowSorting="false" AllowFiltering="false"></telerik:GridBoundColumn> 
                    <GridRadComboFilter:GridRadComboFilter DataField="FlagID" HeaderText="Flag" SortExpression="FlagID" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="50" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50" />   
                    <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" SortExpression="Priority"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="AssignedTo" HeaderText="Assigned To" SortExpression="AssignedTo"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Site" HeaderText="Site" SortExpression="Site"></telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Product" HeaderText="Product" SortExpression="Product"></telerik:GridBoundColumn > 
                    <telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status"></telerik:GridBoundColumn > 
                    <telerik:GridDateTimeColumn DataField="RequestedCompletionDate" SortExpression="RequestedCompletionDate" HeaderText="Req Completion Date" PickerType="DatePicker" DataFormatString="{0:d}" DataType="System.DateTime"></telerik:GridDateTimeColumn> 
                    <telerik:GridBoundColumn DataField="Issue" HeaderText="Issue" SortExpression="Issue"></telerik:GridBoundColumn > 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
 

Server-Side:

 

            With TasksGrid  
                .AutoGenerateColumns = False 
                .AllowFilteringByColumn = True 
                .AllowSorting = True 
                .MasterTableView.AllowMultiColumnSorting = True 
                .AllowPaging = True 
                .PagerStyle.Position = GridPagerPosition.TopAndBottom  
                .PagerStyle.AlwaysVisible = True 
                .PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric  
                .PageSize = TasksGridPageSize.Text  
                .ClientSettings.ClientEvents.OnCommand = "TasksGridCommand" 
                .MasterTableView.ShowHeadersWhenNoRecords = True 
                .MasterTableView.NoMasterRecordsText = "No tasks meet the selected criteria." 
                .DataSource = oDataTable 
            End With  
 

TasksGridCommand javascript function:
                function TasksGridCommand(sender, eventArgs) {  
                    if (eventArgs.get_commandName() == 'PageSize') {  
                        document.getElementById('<%=TasksGridPageSize.ClientID %>').value = eventArgs.get_commandArgument();  
                    }  
                }  
 

0
Tsvetoslav
Telerik team
answered on 02 Sep 2009, 02:54 PM
Hi Ryan,

The OnCommand client event is related to the client-side databinding of the grid. When you are using the OnCommand event and at the same time binding the grid on the server, in order to display the no records template, just add the following lines to the pageLoad client-side event:

            function pageLoad()  
            {                  
                var dataSource = [];  
                $find('<%=RadGrid1.ClientID %>').get_masterTableView().set_dataSource(dataSource);  
                $find('<%=RadGrid1.ClientID %>').get_masterTableView().dataBind();  
           
            } 

I hope this information helps.

Regards,
Tsvetoslav
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
Ryan
Top achievements
Rank 1
answered on 02 Sep 2009, 08:57 PM
Thanks for the reply.  I tried what you said below, and sure enough, my NoMasterRecordsText shows up.  There's only one problem, why would I want to bind the grid to an empty data source on the client side (or server side for that matter)?  This basically insinuates that I have to track whether there will be records in the datasource or not and take care of showing the NoMasterRecordsText myself, which seems unnecessary.  I guess my new question is whether there is a better way to capture when the user is changing the page size using the built in combo without using the OnCommand event?
0
Tsvetoslav
Telerik team
answered on 04 Sep 2009, 08:02 AM
Hello Ryan,

You can achieve this through a simple check:

            function pageLoad() {  
               
                var dataSource = [];  
                  
                var tableView = $find('<%=RadGrid1.ClientID %>').get_masterTableView();  
                
                if (tableView.get_dataItems().length == 0) {  
                  
                    $find('<%=RadGrid1.ClientID %>').get_masterTableView().set_dataSource(dataSource);  
                    $find('<%=RadGrid1.ClientID %>').get_masterTableView().dataBind();  
                }  
 
            } 

If you do not want to use the OnCommand event of the grid to detect that a page-size-change event has been triggered, you can obtain a reference to the page-size combo in code-behind and attach an event handler to its client SelectedIndexChanged event:

    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridPagerItem)  
        {  
 
            GridPagerItem item = e.Item as GridPagerItem;  
 
            RadComboBox combo = item.FindControl("PageSizeComboBox"as RadComboBox;  
 
            combo.OnClientSelectedIndexChanged = "selectedIndexChanged";  
 
        }  
    } 
<script type="text/javascript">  
 
      function selectedIndexChanged(sender, args)  
      {  
          //your client application logic goes here  
      }          
          
</script> 

I hope the above suggestions will prove useful to you.

Greetings,
Tsvetoslav
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
Ryan
Top achievements
Rank 1
answered on 04 Sep 2009, 12:27 PM
Thanks for the suggestions.  I understand the first solution.  It just seems strange to me that if I don't use the OnCommand client event then the grid knows how and when to show the NoMasterRecordsText with no additional code.  The second solution works well, but if you have the PagerStyle.Position set to GridPagerPosition.TopAndBottom, only the combo you actually change the page-size with retains it's selected value after the postback (via Ajax).  My solution is to just capture PageSizeChanged event server-side and that seems to work well.  I'll add that it also seems odd that there is a PageSizeChanged server event, but no equivalent (built in) client event exists.  Thanks for your help.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Alex
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or