Telerik RadGridView with a paginated RadDataServiceDataSource stops paging if I edit the source

1 Answer 79 Views
DataServiceDataSource GridView
Brad
Top achievements
Rank 1
Brad asked on 10 Sep 2023, 10:28 AM

I have downloaded the Telerik provided example Telerik xaml-sdk\DataServiceDataSource to investigate using the Telerik RadGridView and its pagination behaviors against an OData webservice. For the most part this is working as I expected however I have one other requirement.

I have provided a screenshot of some functionality that allows a user to build their own custom subset of the information displayed by moving rows from the original source to another separate list however when a record is removed from the DataServiceSource the pagination is disabled as it detects that a change is present.

I need the DataServiceSource to be bound to the grid so that the filtering and paging works against the OData API as intended but this precludes me from getting the list building to work.

Is there a way we can disable this internal change tracking or is there some other components we could use?

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 Sep 2023, 03:36 PM

Hello Brad,

The setting that disables the data operations over the RadDataServiceDataSource on data changed cannot be changed. If you want to be able to continue paging, you will need to submit your changes after the collection is changed. To do so, you can call the SubmitChanges method of the RadDataServiceDataSource object. However, note that for that to work you should have write access to the associated service. This won't work in the SDK example you mentioned because it uses a Microsoft service which data cannot be edited.

Also, you can take a look at the RadEntityFrameworkDataSource and see if that suites your needs better.

And as a final suggestion, you can implement wrappers for the service models and use them to populate the UI. Then, manually sync the wrappers data with the service models.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Brad
Top achievements
Rank 1
commented on 14 Sep 2023, 04:11 AM

Hi Martin,

The purpose of the control I am creating is to be able to create a custom subset of the data loaded by the OData API, I want to be able to modify the collection visually but I never want to change the data in the backend in any way.

I took a look at the RadEntityFrameworkDataSource but it seems to have to be initialized with a database directly and not with an OData API so that won't work for our situation. If this is not the case please let me know. Even with the database directly it seems to have the same requirement that when I remove items I need to submit the changes which actually modifies the backend data which I never want to do.

I am not sure I really understand the last suggestion perhaps you could elaborate more or provide an example?

My requirements are that I need to have a data source that I can bind to the Telerik RadGridView that allows me to page the results and filter/sort against the source (not just the records in memory on the screen). I also need to be able to move items in an out of the collection without disabling these behaviors. An example of this would be ideal if possible.

Martin Ivanov
Telerik team
commented on 18 Sep 2023, 11:52 AM

You are correct, in order to use OData API the RadEntityFrameworkDataSource won't do the work. One idea that you can explore is to use a custom implementation of QueryableDataServiceCollectionView<T> instead of the RadDataServiceDataSource. This is the class used for the DataView of the RadDataServiceDataSource. The custom implementation of the collection view class can override its CanChangePage property and MoveToPageCore method. 

public class CustomQueryableDataServiceCollectionView<T> : QueryableDataServiceCollectionView<T> where T : class, INotifyPropertyChanged
{
	public CustomQueryableDataServiceCollectionView(DataServiceContext dataServiceContext, DataServiceQuery<T> dataServiceQuery) 
		: base(dataServiceContext, dataServiceQuery)
	{
	}

	public override bool CanChangePage
	{
		get
		{
			return true;
		}
	}

	protected override bool MoveToPageCore(int index)
	{
		HasChanges = false;
		var result = base.MoveToPageCore(index);           
		return result;
	}
}

However, keep in mind that this approach is not well tested and I cannot tell if it is going to work properly in all expected cases.

About the suggestion with the wrappers, what I had in mind is that you can create new classes representing the data that should be placed in the GridView and then populate collection of these models manually. The downside of this approach is that you should either work with the full data or implement the data fetching operations manually.

public class MainViewModel
{
	private MyNorthwindContext serviceContext;

	public ObservableCollection<OrderWrapper> Orders { get; set; }

	public MainViewModel()
	{
		serviceContext = new MyNorthwindContext();
		var ordersQuery = serviceContext.Orders;
		var orderWrappers = ordersQuery.Select(x => new OrderWrapper() 
		{ 
			OrderID = x.OrderID
		});

		Orders = new ObservableCollection<OrderWrapper>(orderWrappers);
	}
}

public class OrderWrapper
{
	public int OrderID { get; set; }
}

Tags
DataServiceDataSource GridView
Asked by
Brad
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or