Hello,
I've got a web data grid setup like the following:
<ig:WebDataGrid ID="wdgSearch" runat="server" AutoGenerateColumns="False" EnableViewState="true" EnableDataViewState="true" OnColumnSorted="wdgSearch_ColumnSorted" >
<Columns>
<ig:BoundDataField DataFieldName="prikey" Key="prikey" Hidden="True" />
<ig:BoundDataField DataFieldName="ShipListNbr" Key="ShipListNbr" Width="100px" >
<Header Text="Ship List #" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="ExceptionCode" Key="ExceptionCode" Width="100px">
<Header Text="Exception Code" />
<ig:BoundDataField DataFieldName="ShortDescr" Key="ShortDescr" Width="200px">
<Header Text="Exception Description" />
<ig:BoundDataField DataFieldName="userID" Key="Count" Width="50px" >
<Header Text="Count" />
<ig:BoundDataField DataFieldName="Name" Key="Name" Width="150px" >
<Header Text="Name" />
<ig:BoundDataField DataFieldName="lastmoddate" Key="lastmoddate" Width="150px" >
<Header Text="Date" />
</Columns>
<Behaviors>
<ig:ColumnResizing>
</ig:ColumnResizing>
<ig:Sorting SortingMode="single" Enabled="true">
<ColumnSettings>
<ig:SortingColumnSetting ColumnKey="ShipListNbr" Sortable="true" />
<ig:SortingColumnSetting ColumnKey="ExceptionCode" Sortable="true" />
<ig:SortingColumnSetting ColumnKey="ShortDescr" Sortable="true" />
<ig:SortingColumnSetting ColumnKey="userID" Sortable="true" />
<ig:SortingColumnSetting ColumnKey="Name" Sortable="true" />
<ig:SortingColumnSetting ColumnKey="lastmoddate" Sortable="true" />
</ColumnSettings>
</ig:Sorting>
</Behaviors>
<EmptyRowsTemplate>
No data to display...
</EmptyRowsTemplate>
</ig:WebDataGrid>
I have a dynamic SQL query that I build up in the code behind and bind a data table to the grid to populate it - that works fine and the data displays nicely.
I also want to sort the grid, and tried to use the _ColumnSorted method to update the sort, but the grid itself is not sorting. The sort indicator displays, but the grid remains in the same order. Here's the _ColumnSorted sub
Protected Sub wdgSearch_ColumnSorted(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.SortingEventArgs)
' Clear out the old sort
wdgSearch.Behaviors.Sorting.SortedColumns.Clear()
' Update the new sort
wdgSearch.Behaviors.Sorting.SortedColumns.Add(wdgSearch.Columns(e.Column.Key), Infragistics.Web.UI.SortDirection.Ascending)
End Sub
Basically I want to clear any old sorted columns out, then add the new column to the sorted columns collection.
Based on what I'm reading in the documentation, I'd expect this to work, but it isn't.
Any help would be greatly appreciated.
thanks,
Jeff Balcerzak
I realize this is old, but you need to change the sort order in your even handler:
protected void WebDataGridMain_ColumnSorted(object sender, SortingEventArgs e) { // First try to get the direction of the requested column. We should get an exception if the // column to be sorted isn't the currently sorted column. In that case we will default to // ascending. Infragistics.Web.UI.SortDirection sortDirection = Infragistics.Web.UI.SortDirection.Ascending; try { sortDirection = e.SortedColumns[e.Column.Key].SortDirection; } catch { sortDirection = Infragistics.Web.UI.SortDirection.Ascending; } WebDataGridMain.Behaviors.Sorting.SortedColumns.Clear(); WebDataGridMain.Behaviors.Sorting.SortedColumns.Add(e.Column.Key, sortDirection); }
Awesome - I'll give that a try. Nobody has complained about the sorting yet, but I know I've got a couple new projects coming up where it will be needed, so this will be great if I can get it to work.