Hi,
I have this data grid in an updatepanel. The sorting and filtering is not working. I see the loading icon, but the grid is not udpated. To get the sorting working, I attached to the sorted event and then I rebind the grid from the server and it does the trick. Same thing for filtering. As long as I don't post back the updatepanel, the grid is not refreshed.
This is what I have in the aspx:
<asp:UpdatePanel ID="dataGridUpdPnl" runat="server" UpdateMode="Conditional"> <ContentTemplate> <ig:WebDataGrid ID="reportDataIGGrd" runat="server" AutoGenerateColumns="false" InitialExpandDepth="0" InitialDataBindDepth="0" EnableDataViewState="true" OnColumnSorted="ReportData_ColumnSorted" OnDataFiltered="ReportData_Filtered" DataKeyFields="Report" EnableAjax="true" AjaxIndicator-Enabled="True" AjaxIndicator-BlockArea="Control" AjaxIndicator-BlockCssClass="ig_AjaxIndicatorBlock" OnPageIndexChanged="reportDataIGGrd_PageIndexChanged" Height="100%" Width="100%"> <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:Selection RowSelectType="Multiple" CellClickAction="Row" Enabled="true" /> <ig:Sorting SortingMode="Single" Enabled="true" /> <ig:Filtering Alignment="Top" Visibility="Visible" Enabled="true" AnimationEnabled="true" /> </Behaviors> <EmptyRowsTemplate> <div style="text-align: center;"> <br /> <br /> <img src="~/../Images/attention.png" alt="!" align="middle" /> <asp:Label ID="noDataLabel" runat="server" Text="No records found." Font-Size="Small" ForeColor="#000099" Font-Bold="True"> </asp:Label> </div> </EmptyRowsTemplate> <ErrorTemplate> <div style="text-align: center; width: 800px;"> <img src="~/../Images/error.png" alt="!" align="middle" /> <asp:Label ID="errorLabel" runat="server" Text="An error has occurred! Please contact support." Font-Size="Small" ForeColor="#CC0000" Font-Bold="True"> </asp:Label> </div> </ErrorTemplate> <ClientEvents Initialize="intializeGrid" /> </ig:WebDataGrid> <igui:WebResizingExtender ID="reportGridIGResize" runat="server" TargetControlID="reportDataIGGrd" /> <uc1:ReportPagingControl ID="reportPagingCtl" Visible="false" CollectionKey="ReportData" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="refreshBtn" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="clearAllBtn" EventName="Click" /> </Triggers> </asp:UpdatePanel>
Thanks
I am facing the same issue were u able to resolve this. Kindly reply if u found a solution for tis.
Hi
Yes, I did fix the issue, but it's been a while and will have to rely on my memory to give you an answer since I run in many issues at the time with the grid. From what I can remember, the issue was that I was not setting the datasource when the grid was filtering, sorting or paging. Each time a user post a filter, paging or sorting event, you have to set the grid data source in the page.load. You should not need to call the bind() method on the grid.
The thing you have to be careful about is when the user perform changes in the grid. if the user performs a change in the grid and you set the datasource before reading the information, you will lose the information. The main problem (from what I can remember) is that in the onload, the grid field information is not available.
So, to get around the information loss issue, I used a hidden field to flag if the request was posted using a filter, paging or sorting event. To do this, I added these to the behaviours:
<Behaviors>
<ig:Activation Enabled="true" />
<ig:Selection RowSelectType="Multiple" CellClickAction="Row" Enabled="true" />
<ig:Sorting SortingMode="Single" Enabled="true" SortingClientEvents-ColumnSorting="SetGridAction" SortingClientEvents-ColumnSorted="ClearGridAction"/>
<ig:Filtering Alignment="Top" Visibility="Visible" Enabled="true" AnimationEnabled="true" FilteringClientEvents-DataFiltering="SetGridAction" FilteringClientEvents-DataFiltered="ClearGridAction" />
<ig:Paging PagerAppearance="Both" PagerMode="NumericFirstLast" PagingClientEvents-PageIndexChanging="SetGridAction" PagingClientEvents-PageIndexChanged="ClearGridAction"
QuickPages="3" PageSize='<%$ appSettings:PageSize_ReportDataMapGrid%>'
FirstPageText="First" LastPageText="Last" >
</ig:Paging>
</Behaviors>
The SetGridAction and ClearGridAction functions are javascript functions that sets or clear my hidden field value. Once you did this, all you have to do in the page.load, is to check for the hidden input value and only set the grid datasource if the hidden value was set.
I hope this helps
Yves
Hey,
Thank you sooo much for the response. Sorting and filtering functionalities are working perfectly fine now :)
My requirement is to save these sorted and filtered records into the cache and use it in another page. But the object in the page load will have the whole table values and not the filtered and sorted values. Is there any way to save the filtered and sorted values from the grid into a datatable from the code behind?
Arahanth
There are many ways to approach this depending on the volume of data you are dealing with, but the simpliest solution would be to create another datatable with the same structure than the original one and populate this datatable using the filtered row in the grid.
To do this, you would have to perform the filtering in the page.load, which you do now, and then from the page.onprerender, you could create your new datatable, populate it with the filtered data and then cache it. To read the filtered data, you can use the grid.Rows[index].DataItem object that would contain the DataRow from the originating (filtered) data table.
After filtering and sorting the records I have 120 records. Since the data has been paged, i am getting only the rows of one page in the grid.Rows[index] object.
I have written the following code to retrieve the values from all the pages using
void Page_Prerender(object sender, EventArgs e)
{
DataRecordCollection MyFilteredData = WebDataGrid1.GetDataView().DataAdapter.Records;
if (MyFilteredData != null)
DataTable dt = new DataTable();
foreach (DataRecord dr in MyFilteredData)
DataRowView drv = (DataRowView)dr.DataItem;
DataRow drow = drv.Row;
dt.Rows.Add(drow); This line shows an exception saying the row already belongs to another table
I am able to get all the paged rows in the myfilterdatacolection. Is my approach right? Kindly suggest a solution to the exception i am getting.
You cannot add a row from table to another. A row can only belong to one table. Here's how you copy a datatable to another:
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(new object[] { 2, "Name" });
dt.AcceptChanges();
//Here, we copy the info from dt to dt2
System.Data.DataTable dt2 = dt.Clone();
foreach (System.Data.DataRow dr in dt.Rows)
dt2.Rows.Add(dr.ItemArray);
}
dt2.AcceptChanges();
Everything loks good.