We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Sorting not working for columns that are bound to collection items

Thread ID:

Created:

Updated:

Platform:

Replies:

131153 Jun 23,2017 03:46 PM Jun 27,2017 05:24 AM WPF 3
loading
Tags: SfDataGrid
Ryan Lim
Asked On June 23, 2017 03:46 PM

I want to bind a column to a value at a particular index in a List or a particular key in a Dictionary.  The values display properly in the grid however when I attempt to sort by that particular column the grid stops responding.  I pasted some sample code that reproduces the problem.  This grid will build and display correctly but once sorted by either the C3 or C4 column it will not sort and also clicking on the C1 and C2 column headers will no longer work.

class TestData
{
public string C1 { get; set; }
public decimal C2 { get; set; }
public List<int> C3 { get; set; }
public Dictionary<string, int> C4 { get; set; }
}

void BuildGrid(SfDataGrid grid)
{
     grid.AllowSorting = true;

grid.Columns.Add(new GridTextColumn()
{
HeaderText = "C1",
MappingName = "C1",
AllowSorting = true,
AllowResizing = true
});

grid.Columns.Add(new GridNumericColumn()
{
HeaderText = "C2",
MappingName = "C2",
AllowSorting = true,
AllowResizing = true
});

grid.Columns.Add(new GridNumericColumn()
{
HeaderText = "C3",
MappingName = "C3[0]",
AllowSorting = true,
AllowResizing = true
});

grid.Columns.Add(new GridNumericColumn()
{
HeaderText = "C4",
MappingName = "C4[C4]",
AllowSorting = true,
AllowResizing = true
});

var data = new List<TestData>
{
new TestData 
C1 = "1", 
C2 = 1M, 
C3 = new List<int> { 1, 11, 111 }, 
C4 = new Dictionary<string, int> { { "C4", 1 } }
},
new TestData 
C1 = "2", 
C2 = 2M, 
C3 = new List<int> { 2, 22, 222 }, 
C4 = new Dictionary<string, int> { { "C4", 2 } }
}
};
grid.ItemsSource = data;
}


Is there anything that I am missing here that might be causing the grid to behave this way?

Thanks


Srinivasan Vasu [Syncfusion]
Replied On June 26, 2017 02:55 AM

Hi Ryan, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query and we have prepared a sample as per your provided details. If the data operations are not working as expected while using indexer or dictionary property in the Underlying Collection, set GridColumn.UseBindingValue as true. 
 
Please refer the below code  
 
   this.datagrid.Columns.Add(new GridNumericColumn() 
            { 
                HeaderText = "C3", 
                MappingName = "C3[2]", 
                AllowSorting = true, 
                AllowResizing = true, 
                UseBindingValue = true, 
            }); 
 
  
 
Please refer the below UG Link: 
 
 
Regards, 
Srinivasan 


Ryan Lim
Replied On June 26, 2017 01:58 PM

That did the trick.  I took the following code in my sample:

grid.Columns.Add(new GridNumericColumn()
{
     HeaderText = "C3",
     MappingName = "C3[0]",
     AllowSorting = true,
     AllowResizing = true
});

I then just made a single line change in the code to:

grid.Columns.Add(new GridNumericColumn()
{
     HeaderText = "C3",
     MappingName = "C3[0]",
     AllowSorting = true,
     AllowResizing = true,
     UseBindingValue = true
});

Sorting now works.  Thanks for the quick response!


Muthukumar Kalyanasundaram [Syncfusion]
Replied On June 27, 2017 05:24 AM

Hi Ryan, 
 
Thanks for the update. Please let us know if you need any other assistance. 
 
Regards, 
Muthukumar K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;