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

Radgrid not loading new data on postback after sort

5 Answers 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Munish Sharma
Top achievements
Rank 1
Munish Sharma asked on 22 Aug 2013, 12:26 AM
I am working on a radgrid which loads from datatable at runtime under NeedDataSource event. The grid is very dynamic and loads different columns in different cases. Everything works fine till I sort the column(either ascending or descending) and then do a postback to load new columns. When I do this it just fails to load the new changes.

Note: If I don't sort the column everything works fine. 

<telerik:RadAjaxManagerProxy ID="ampAnalysis" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rgAnalysis">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rgAnalysis" LoadingPanelID="LoadingPanel"/>
                    </UpdatedControls>
                </telerik:AjaxSetting>                
            </AjaxSettings>
        </telerik:RadAjaxManagerProxy>
        
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
            <telerik:RadGrid ID="rgAnalysis" runat="server" ShowGroupPanel="false" Skin="Default" 
                AllowMultiRowSelection="True" AllowSorting="True" GridLines="None" BorderStyle="None" BorderWidth="0"   
                Height="500px" ShowFooter="True"  Width="100%" EnableViewState="False"
                AllowFilteringByColumn="True" PagerStyle-Mode="Slider" PageSize="12" AllowPaging="true" OnItemCommand="rgAnalysis_ItemCommand" >
                <GroupingSettings CaseSensitive="false" />
                <ExportSettings>
                    <Csv ColumnDelimiter="Tab" RowDelimiter="NewLine" FileExtension="txt" />
                    <Excel Format="Html" />
                    <Pdf FontType="Subset" PaperSize="Letter" AllowAdd="false" AllowCopy="false" AllowModify="false" AllowPrinting="true" Creator="ABI" 
                        PageBottomMargin="5mm" PageTopMargin="20mm" PageLeftMargin="5mm" PageRightMargin="5mm" PageHeight="297mm" PageWidth="420mm" />
                </ExportSettings>
                <FooterStyle HorizontalAlign="Right" Font-Bold="false"/>
                <MasterTableView AllowNaturalSort="true" ShowFooter="True" AllowMultiColumnSorting="true" EnableViewState="false" Width="100%">
                    <Columns>
                        <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="50px" ItemStyle-Width="30px" />
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <DataBinding EnableCaching="true"></DataBinding>
                    <Resizing ResizeGridOnColumnResize="true" />
                    <selecting AllowRowSelect="True" />
                    <Scrolling AllowScroll="True" SaveScrollPosition="true" FrozenColumnsCount="3">
                    </Scrolling>
                    <ClientEvents  OnRowSelected="rgAnalysis_RowSelected"  OnRowDeselected="rgAnalysis_RowDeselected" />
                </ClientSettings>
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Aug 2013, 10:24 AM
Hi Munish Sharma,

RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime
. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file.This may be the issue which is causing such an undesired behavior in your code.Another best practice is to either use RadAjaxManagerProxy or RadAjaxPanel in your scenario,not both together.
Please provide your code behind as well if this doesn't help.

Thanks,
Princy
0
Munish Sharma
Top achievements
Rank 1
answered on 22 Aug 2013, 10:58 PM
Princy,

It's nothing to do with the RadAjaxManagerProxy or RadAjaxPanel. As I said the grid works perfectly fine in most all the cases except just this one. There is no other issue with the functionality. 

Say my report1 has column1, column2, column3
and
report2 has column4, column5, column6

When I run report1, it shows me the column1, column2 & column3 and when I run report2 it shows me column4, column5, column6

But the problem comes when I run report1 and sort any column(column1 or column2 or column3) and then try running report2. Here it goes to needdatasource event and get the data for report2 and then crashes somewhere without any exception. I tried debugging it and found that it only comes once in column created event when I do the sort and run the second report. When I don't do the sort and run the second report it comes multiple times to column created event.


I have attached Images when it works without sorting (Without Sort 1, Without Sort 2, Without Sort 3)
I have also attached Images when it doesn't work with sorting(With Sort 1,With Sort 2,With Sort 3, With Sort 4)

I have added GridClientSelectColumn to get checkboxes for every row in grid. And yes we can add columns dynamically with the GridClientSelectColumn from datatable in need datasource.

Moreover, telerik:RadAjaxPanel is enclosed around the grid to call javascript as:
RadAjaxPanel1.ResponseScripts.Add("PrintRadGrid('" + rgAnalysis.ClientID + "')")

Javascript:
function PrintRadGrid(radGridId) {
            var radGrid = $find(radGridId);

            if ($telerik.isIE) 
            {
                if (document.getElementById('ctl00_cphCenter_rgAnalysis_ctl00').style.tableLayout == 'fixed') 
                {
                    document.getElementById('ctl00_cphCenter_rgAnalysis_GridFooter').style.width = '100%';
                    document.getElementById('ctl00_cphCenter_rgAnalysis_GridHeader').style.width = '100%';
                    document.getElementById('ctl00_cphCenter_rgAnalysis_GridData').style.overflow = 'visible';
                }
                else 
                {
                    if (document.getElementById('ctl00_cphCenter_rgAnalysis_ctl00').style.tableLayout == 'auto') 
                    {
                        document.getElementById('ctl00_cphCenter_rgAnalysis_GridData').style.overflow = 'visible';
                    }
                }
            }

0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2013, 06:06 AM
Hello Munish Sharma,

I am agree with @princy. But if you faced only sorting issue then can you please try with the below code snippet.


RadGrid1.MasterTableView.SortExpressions.Clear();

Issue : As per screenshot you have applied sorting in sales column then you are binding the report2 data.
So, grid will remove reaport1 column and add report2 column then it will apply sales column sorting expression. in this binding process this will not able to find sales column in the grid so it will raised the Java-script error. So, Before rendering the radgrid it get the error so you are not to see changes in radgrid.

Solution : Before applied/changing the databind()/datasource from report1 to report2 or report2 to report1. Please clear the sort expression from the radgrid.


Thanks,
Jayesh Goyani
0
Munish Sharma
Top achievements
Rank 1
answered on 25 Aug 2013, 10:18 PM
Hi Jayesh,

I am already using the sort clear command under postback before NeedDataSource but still the same problem./

command:
rgAnalysis.MasterTableView.SortExpressions.Clear()

Munish
0
Munish Sharma
Top achievements
Rank 1
answered on 30 Aug 2013, 04:33 AM
I have found the fix. I just needed to add another few lines of code on Form_Load event:

If Not Page.Request.Params.[Get]("__EVENTTARGET") Is Nothing Then
            If Page.Request.Params.[Get]("__EVENTTARGET").Contains("pnlReporting") Then
                rgAnalysis.MasterTableView.SortExpressions.Clear()
                rgAnalysis.DataBind()
            End If
        End If
Tags
Grid
Asked by
Munish Sharma
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Munish Sharma
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or