I have 2 grids with the same column layout side by side. I have filters enabled on the left grid, and when records are filtered out, I move them to the right side grid. I use the RecordFilterChanged event and iterate through the records calling e.RecordFilter.MeetsCriteria(record) to determine which records to move to the right side grid. Ie:
if (!e.RecordFilter.MeetsCriteria(leftSideRecord))
//move to the right side grid
Is there a way to determine which records to move back to the left side grid when the filter changes? Eg. I clear one of my filters on the left side, and I'd like to evaluate the records on the right side to determine if any can now be moved left. I don't see any obvious way to get all the applied filters on a grid so that I can evaluate my right side records.
Hello kobieb,
I have been investigating into this, and I imagine that to move the records from one grid to another, you are essentially taking the DataRecord.DataItem and adding it to the collection bound to the "filtered out" XamDataGrid. If this is not the case, please let me know, as the following is based on that assumption.
In order to determine which records should be moved between your XamDataGrid instances, I would recommend that you use some code like the following in the RecordFilterChanged event of the XamDataGrid:
RecordFilter filter = e.RecordFilter;foreach (var x in XDGFilterIn.Records){ if (x is DataRecord) { DataRecord record = x as DataRecord; if (!filter.MeetsCriteria(record)) { if (!vm.FilterOutData.Contains(record.DataItem)) { vm.FilterOutData.Add(record.DataItem as SampleData); } } else { vm.FilterOutData.Remove(record.DataItem as SampleData); } }}
With the above code, the vm.FilterOutData is the collection that is bound to the secondary "filtered out records" grid. In this case, the records are never really removed from the "filtered in" grid, as them not meeting the filter conditions will hide them from the user anyway, and so they don't really need to be removed. In the if-else statements listed above, each record in the "filtered in" grid (XDGFilterIn) is checked to see if the e.RecordFilter is met. If not, and if it doesn't already exist in the collection bound to the "filtered out" grid, its underlying DataItem (in this case, a SampleData instance) is moved to the "filtered out" grid's DataSource. Otherwise, it can be assumed that since the record does not meet the criteria, the data item already exists in the "filtered out" grid's data source and can be removed.
I have attached 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.
Sincerely,AndrewAssociate Developer
Thanks for the response, Andrew. Unfortunately, just hiding the records in the left side grid is not sufficient, as I need to actually remove them from the collection. I'll see if there's a way around this, but ideally, there'd be some way to apply a filter to a DataRecord that is not part of the left side grid (XDGFilterIn in your example).
There was a bit that I had originally left out of my original response, and I apologize for doing so. If the reason for removal of the records in this case is to truly only get the filtered in and filtered out records in the XamDataGrid, there exists a method for that on the XamDataGrid.RecordManager named GetFilteredInDataRecords/GetFilteredOutDataRecords. This can get you all of the records that satisfy(or don't) a set of filters applied to your XamDataGrid without the need to loop through each of the records in the XamDataGrid.Records collection.
If you still wish to continue with the removal of the records on each side of the grid, know that the application of the MeetsCriteria method on each of the records in your separate grid will always return true. This is because the RecordFilter will use its Field property, which returns the actual Field object for your "Filtered In" grid in this case. This Field object will be a different instance than the one in the "filtered out" grid, and so it will not be found. In this case, I would recommend constructing an equivalent RecordFilter object by looping through the Conditions collection of your e.Filter and applying a FieldName property to the RecordFilter by using the Field.Name of the e.Filter.
Once you have done this, you can check the criteria of your new RecordFilter object against the records in the "filtered out" grid. Using the GetFilteredIn and GetFilteredOut DataRecord methods mentioned above, you can also get the corresponding data items to move back and forth between your grids as necessary. I have attached a sample project to demonstrate how this can be done.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Thanks Andrew. This helped a great deal.