Cant edit cells when using sfdatapager and datasource is a list
Hello, I'm currently using SfDataGrid to display data from multiple tables. The problem is that in some I need editing to be allowed, but even though it is indeed allowed when I run the app and click on the cells nothing happens, it is read only.
Because sfdatapager does not accept datatable, I'm converting it to a ienumerable list as the component requires, and the data displays. Heres some code
// This is where the source is loaded, editing is allowed by default, nothing is changed
var data = ListConverter.DTListConverter(table, TableName);
sfDataPager.DataSource = data;
sfDataPager.PageSize = 100;
tableGrid.DataSource = sfDataPager.PagedSource;
//This is the converter
data = table.AsEnumerable().Select(row =>
new
{
UniqueId = row["UniqueId"].ToString(),
postalCode= row["postalCode"].ToString(),
countryCode= row["countryCode"].ToString(),
stateCode= row["stateCode"].ToString(),
description= row["description"].ToString(),
suc= row["suc"].ToString(),
region= row["region"].ToString(),
frequency= row["frequency"].ToString(),
});
As I mentioned before, the data is displaying correctly in the grid. The only problem is that I cant trigger the edit. Is there a way to solve this or a better way to convert
Hi Alejo Yanczuk,
The reported problem occurs due to you are created the property with the getter
alone. Refer to the below screenshot,
If you need to make this property editable, then you should create the property
along with a setter as shown below.
|
public class OrderInfo : INotifyPropertyChanged {
string customerId;
public string CustomerID { get { return customerId; } set { customerId = value; this.OnPropertyChanged("CustomerID"); } } }
var table = this.GetDataTable(); //This is the converter var data = table.AsEnumerable().Select(row => new OrderInfo { OrderID = decimal.Parse(row["OrderID"].ToString()), CustomerID = row["CustomerID"].ToString(), CustomerName = row["CustomerName"].ToString(), Country = row["Country"].ToString(), ShipCity = row["ShipCity"].ToString()
});
|
Find the sample demo in the attachment.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Attachment: SfDataGridDemo_cc9622d2.zip
- 1 Reply
- 2 Participants
- Marked answer
-
AY Alejo Yanczuk
- Apr 18, 2023 08:54 PM UTC
- Apr 19, 2023 02:35 PM UTC