Hi,
I am using 2012.2 release. We have a webdatagrid which has sorting enabled:
<ig:Sorting Enabled="true" SortingMode="Multi" />
The problem is every time we want to sort by the column, we need to click on the column header twice, the first click does add the sorting image to the column header, but the data is not sorted correctly, the 2nd click will sort the the data correctly.
Any help will be appreciated!
Qiuyu
Hello Qiuyu,
Thank you for contacting Infragistics using forum!
Based on your information, I have created an isolated sample application and try to reproduce the behavior but it was not able to replicate and sorting is working fine without any issue.
I have attached the sample project I used to test this, please test the sample application and let me know. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem. My test was performed using version 12.2.20122.2107 CLR 4.0.
One more thing I would like to add with my last reply, that is if you are binding the WebDataGrid using the if (!IsPostBack) { // databinding code here }
You should handle the WebDataGridProposedProject_ColumnSorted event and rebind the grid again to have sorting effect on the grid look like that:
protected void WebDataGridProposedProject_ColumnSorted(object sender, Infragistics.Web.UI.GridControls.SortingEventArgs e) { DataTable dt = getdata(); this.WebDataGridProposedProject.DataSource = dt; this.WebDataGridProposedProject.DataBind(); }
Otherwise only column sort indicator will be changed and no sorting will be applied on the grid. Please test this also. Thank you.
Incase if you are still facing any issue please feel free to modify the sample application I have provided to you and revert I will look at that and try to help you on this. Thank you.
I also face the same issue of having to click twice when using hyperlinks as templatecolumns. The first click does nothing and only on the 2nd click does it actually sort.
Please help..!This is urgent
here is a markup of the code.
Here is the code:
<script type="text/javascript" id="igClientScript">
//initial sorting direction
var lastSortDirection = 2;
var sortAscImage = "";
var sortDescImage = "";
function setSortAscLocation(sortIconImageAsc)
{
sortAscImage = sortIconImageAsc;
}
function setSortDescLocation(sortIconImageDesc)
sortDescImage = sortIconImageDesc;
function WebDataGrid1_Sorting_ColumnSorted(sender, eventArgs)
//if the hidden LinkText column is sorted, the sorting images should be displayed for the Link column
if (eventArgs.get_column().get_key() == "NameColumnHidden")
//based on the sort direction we inject Html into the column header's element.
if (lastSortDirection == 2)
var currentHTML = sender.get_columns().get_columnFromKey("NameColumn").get_headerElement().innerHTML;
//note that this is a rough injection of the ascending/descending image into the header
sender.get_columns().get_columnFromKey(
"NameColumn").get_headerElement().innerHTML = currentHTML + " " + "<img src='" + sortAscImage + "'>";
else
"NameColumn").get_headerElement().innerHTML = currentHTML + " " + "<img src='" + sortDescImage + "'>";
function WebDataGrid1_Sorting_ColumnSorting(sender, eventArgs)
//if the link column is being sorted, set the actual sorting to the hidden LinkText column
if (eventArgs.get_column().get_key() == "NameColumn")
eventArgs.set_column(sender.get_columns().get_columnFromKey(
"NameColumnHidden"));
//the sort direction needs to be modified based on the last sort on the link column.
if (lastSortDirection == 1)
eventArgs.set_sortDirection(2);
lastSortDirection = eventArgs.get_sortDirection();
eventArgs.set_sortDirection(1);
</script>
<ig:WebDataGrid Visible="False" ID="MyGrid" runat="server" Width="98%"
OnPreRender="MyGrid_PreRender" OnInitializeRow="MyGrid_InitializeRow" AutoGenerateColumns="False"
DataKeyFields="ID"
<Columns>
<iggrid:BoundDataField Key="ID" DataFieldName="ID" Hidden="true">
</iggrid:BoundDataField>
<iggrid:BoundDataField Header-Text="Name" Key="NameColumnHidden" DataFieldName="Name" Hidden="true">
<Header Text="Name"></Header>
<iggrid:TemplateDataField Key="NameColumn" Header-Text="Name">
<ItemTemplate>
<asp:HyperLink ID="explink" runat="server" ForeColor="Blue" Text='<% #DataBinder.Eval(Container,"DataItem.Name") %>'></asp:HyperLink>
</ItemTemplate>
</iggrid:TemplateDataField>
<Behaviors>
<iggrid:EditingCore>
</iggrid:EditingCore>
<iggrid:ColumnMoving>
</iggrid:ColumnMoving>
<iggrid:Sorting Enabled="True" SortingMode="Single">
<SortingClientEvents ColumnSorting="WebDataGrid1_Sorting_ColumnSorting" ColumnSorted="WebDataGrid1_Sorting_ColumnSorted" />
</iggrid:Sorting>
<iggrid:Paging PageSize="25" QuickPages="25" PagerAppearance="Bottom" FirstPageText="First"
LastPageText="Last" PagerMode="NumericFirstLast" PagingClientEvents-PageIndexChanged="PageIndexChanged">
<PagingClientEvents PageIndexChanged="PageIndexChanged"></PagingClientEvents>
</iggrid:Paging>
<iggrid:Filtering Enabled="False">
</iggrid:Filtering>
</Behaviors>
</ig:WebDataGrid>
did this break in 15.2? I have the issue where the first time you click on a column it does not sort, but the second time you click it sorts based on the previous click, and continues to be 1 click behind as you go... and when I download the samples here it does the same thing. thoughts?
Hello Dev,
Based on your code snippet, I have modified the isolated sample application and try to reproduce the behavior but it was not able to replicate and sorting is working fine without any issue and I am able to do the sorting on single click with your code snippet and javascript codes.
I have attached the modified sample project I used to test this, please test the sample application and let me know. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem. My test was performed using version 12.2.20122.2107 CLR 4.0.
P.S.: **Sample is attached. Please note that the ig_res folder has been omitted due to file size constraints. For proper styling of the grid you will want to add the ig_res folder. To do so, simple open the web form designer (aspx) and accept the styles when prompted.