<
telerik:RadGridView
Grid.Row
=
"1"
Name
=
"adjustments"
CanUserDeleteRows
=
"False"
CanUserInsertRows
=
"False"
CanUserResizeRows
=
"False"
ShowGroupPanel
=
"False"
SelectionChanged
=
"adjustments_SelectionChanged"
ItemsSource
=
"{Binding Path=CurrentClaim.claimAdjustments, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
AutoGenerateColumns
=
"False"
IsReadOnly
=
"True"
MouseDoubleClick
=
"adjustments_MouseDoubleClick"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Name
=
"colCreatedOn"
DataMemberBinding
=
"{Binding createdOn}"
Header
=
"Posting Date"
DataFormatString
=
"{}{0:MM/dd/yyyy}"
SortingState
=
"Descending"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding claimAdjustmentReason.description}"
Header
=
"Reason"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
The property CurrentClaim does notify the grid and the grid does update the data when the new claim is set in CurrentClaim. The problem is that the grid is sorted based on the first column, but when new data is loaded into the grid it is not sorted by this column. Can someone please tell me what I am doing wrong or why the sort doesn't work when new data is loaded?
-Lee
14 Answers, 1 is accepted
Generally the Sorting will be refreshed when a CollectionChanged event is raised from the bound source collection. May I ask you to share how is your ItemsSource defined? How do you load the new data?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
public
static
readonly
DependencyProperty CurrentClaimProperty = DependencyProperty.Register(
"CurrentClaim"
,
typeof
(claim),
typeof
(ClaimData),
new
PropertyMetadata());
public
claim CurrentClaim
{
get
{
return
(claim)GetValue(CurrentClaimProperty); }
set
{ SetValue(CurrentClaimProperty, value); }
}
As you can see in the XAML I posted earlier, this is linked to the grid control. The grid is loaded from the CurrentClaim.claimAdjustments collection. This all seems to work just fine. The only problem is that I have set the grid to sort descending on the date column every time but the grid seems to loose that when a new CurrentClaim is set. It does refresh the claimAdjustments, just does not sort them.
Would you please set the ItemsSource to null, and then set it to the new data to be bound?
Greetings,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
It seems that there is not raised a notification as you refresh the data, the claimAdjustments.
You have three options:
1. Raise a CollectionChanged when the bound collection is changed.
2. Invoke a Rebind() for the RadGridView.
3. Reset the ItemsSource of the RadGridView.
I hope this helps.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
We are facing the same issue in Grid sorting not working on refresh. I tried setting the Grid itemsource to null in Viewmodel and the raised propertychanged followed by binding the grid to correct value but sorting applied in XAML is not working.
<controls2:RadGridView.SortDescriptors>
<telerik:ColumnSortDescriptor Column="{Binding Columns[\MyCustomOrder\], ElementName=MyGridName}"
SortDirection="Ascending" />
</controls2:RadGridView.SortDescriptors>
Thanks,
SK
Does it work the first time the GridView is loaded? Does invoking a RadGridView.Rebind() re-sort the data? If not, then would it be possible for you to isolate the issue in a sample project and send it to us?
Regards,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I hit this issue today.
If the Sort is set in XAML and the data refreshed the grid is no longer sorted.
Doing a Rebind after the data is refreshed does not help either.
However if you sort the grid using the mouse and then refresh the data the grid maintains the correct sorting.
I really want my data to be sorted a certain way for the user when they open the window rather them having to click on the column.
Thanks
Anthony
You say that the issue occurs after refreshing the bound data. Would you please share some more information how do you do so?
When sorting with the user clicking on the column header, then a ColumnSortDescriptor is added to RadGridView.SortDescriptors collection. You can try defining such in XAML.
For example:
<
telerik:RadGridView.SortDescriptors
>
<
telerik:ColumnSortDescriptor
Column
=
"{Binding Columns[\Title\], ElementName=radGridView}"
SortDirection
=
"Ascending"
/>
</
telerik:RadGridView.SortDescriptors
>
Does it work fine that way?
Regards,
Dimitrina
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I am refreshing the data from my ViewModel, which the ItemSource of the RadGridView is bound to. Initially it would be NULL until the data is loaded from the database.
My XAML looks like this:
<telerik:RadGridView x:Name="RadGridView" ItemsSource="{Binding Data}">
And my ViewModel does this after the data is loaded from the database. Data is null previously:
Data = new ObservableCollection<EmployeeWork>(newList);
I have tried setting the initial ColumnSortDescriptor in XAML as per your example and that does not help.
Please note that it also works OK if I load the RadGridView settings from disk after persisting its layout when exiting the application. So it looks like it is only the initial sorting set in XAML that does not work.
Thanks
Anthony
Basically, the defined sorting descriptors will be cleared on reset of the ItemsSource. If this is not the case, may I ask you to open a new support ticket for product RadGridView and send us a demo project illustrating the problem? You can take a look at this blog post for a reference on how to isolate an issue.
That way I will check it locally and suggest a solution.
Regards,
Dimitrina
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I am not sure if your first sentence in the above response is summarizing the issue or telling me that is the designed behaviour?
Also the link in your post is not valid.
Thanks
Anthony
​
I meant that by design the defined SortDescriptors will be cleared if you reset the ItemsSource after setting it to null first and then setting it again. As I understand in your case you refresh it filling data and not resetting it. So then the descriptors should not be cleared. Another approach I can suggest you as to defining a SortDescriptor initially would be to subscribe for the DataLoaded event of RadGridView and add the desired descriptor there.
As to the link, it indeed seems to be not active any more. You can find the correct one here:
http://blogs.telerik.com/aspnet-ajax/posts/10-09-29/isolating-a-problem-in-a-sample-project.aspx
Regards,
Dimitrina
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I managed to work around the issue. I am now setting the default Sort Descriptor in my ViewModel after I set the Data. It's ugly but it works.
Thanks
Anthony