fix: Sorting a column that contains a null value throws exception in FluentDataGrid #1357
Replies: 2 comments
-
Would be great if you can contribute a fix! |
Beta Was this translation helpful? Give feedback.
-
Upon further investigation, this seems to be an issue with Local patchCurrently, I have a patch in my own team's component to check each foreach (DataColumn col in data.Columns)
{
foreach (DataRow row in data.Rows)
{
if (row[col] is DBNull dbNull)
{
switch (col.DataType)
{
case Type t when t == typeof(string):
row[col] = string.Empty;
break;
case Type t when t == typeof(int):
row[col] = 0;
break;
case Type t when t == typeof(double):
row[col] = 0.0;
break;
case Type t when t == typeof(decimal):
row[col] = 0.0m;
break;
case Type t when t == typeof(DateTime):
row[col] = default(DateTime);
break;
case Type t when t == typeof(TimeSpan):
row[col] = default(TimeSpan);
break;
default:
row[col] = null;
break;
}
}
}
} Next stepsThe only change to make to the data grid/related code that I see at the moment is to add an explicit check and conversion for Should this type of fix be added to the components or left to consumers of this library to implement their own fix as needed? Similar issues across the internet over years past |
Beta Was this translation helpful? Give feedback.
-
🐛 Bug Report
I've created a data grid with sortable columns from a System.Data.DataTable object as a source. The columns are of varying types--
string
,bool
,Guid
, etc. When sorting a column that contains aSystem.DBNull
value, anArgumentException
is thrown and the web app crashes. This bug was identified when sorting a column that containsGuid
types but has one or more empty cells. Columns ofstring
types with empty cells do not have the same issue.💻 Repro or Code Sample
In the below sample,
Table
is a component property ofSystem.Data.DataTable?
type.FilteredData
is a component property ofSystem.Linq.IQueryable<DataRow>?
type.The table rows are loaded into an
IQueryable<DataRow>
object through the protected synchronousOnParametersSet()
method:🤔 Expected Behavior
When sorting a column with
DBNull
values, cells with a value ofDBNull
should be treated the same as empty/null cells and not throw an exception.😯 Current Behavior
Below is the stack trace when a column with a null (
DBNull
) value is sorted:💁 Possible Solution
Haven't looked into the code for the FluentDataGrid component yet, but willing to contribute a fix. May just require converting certain types to
null
orstring.Empty
before processing/comparison, or if there's a location in the code higher up to avoid performing this conversion on every sort.🔦 Context
I created a custom component that creates a FluentDataGrid out of an inputted
System.Data.DataTable
. This table is obtained through a Kusto query using the .NET Kusto SDKs, and the data often includes columns that areGuid
type.🌍 Your Environment
Beta Was this translation helpful? Give feedback.
All reactions