Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1450
XamDataGrid - FilteredIn Count
posted

Hi there

In our app we have a record navigator, which shows the count of items of the datasource of a XamDataGrid. But its bound directly to the underlying datasource, so if a user sets any filter, the total count is not updated and not correct anymore. So we would like to bind it to  a property the XamDataGrid which shows the correct total count, accordingly to the set fiter in the XamDataGrid.

When looking into it, i found an old forum post, which says the count could be obtained by:

XamDataGrid.RecordManager.FilteredInDataItems.Count;

But XamDataGrid.RecordManager.FilteredInDataItems is a System.ComponentModel.ICollectionView (in my used Version 2021.2) and does not expose a Count member.

I'm able to get the count like that:

dataGrid.RecordManager.FilteredInDataItems.Cast<object>().Count();

Works fine in all cases i tested it. But is there no better way?
Because if i have to get the count like that, i also have to add a own property to the XamDataGrid which triggers the INotifyPropertyChanged.PropertyChanged to get the Binding in the UI working properly.

That means, i have to update my property at some events like:

XamDataGrid.RecordFilterChanged

XamDataGrid.Loaded (for initialization)

Are there any more which i need to consider? Or is there generally a better way?

Regards

Parents
  • 34430
    Verified Answer
    Offline posted

    Hello Andreas,

    I have been investigating into the behavior you are looking to achieve, and I believe I have found a way to do this using a MultiBinding with a converter. The bindings I am sending in are the XamDataGrid itself and the Version property of the DefaultFieldLayout.RecordFilters collection, as this will increment each time a filter is updated, and as such, will fire the converter. The drawback to this would be if you have a bunch of FieldLayouts, as you would need to add a binding to each one’s Version if you wanted to handle filtering on all of them.

    One caveat to this is that it seems that when this converter fires, the FilteredInDataItems count on the RecordManager is not updated just yet, but the method GetFilteredInDataItems() appears to work correctly, hence why I am passing the XamDataGrid itself instead of XamDataGrid.RecordManager.FilteredInDataItems.

    I am attaching a sample project to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    XDGFilteredInCountTest.zip

Reply Children
No Data