Filter menu broken when undefined on data

undefined values crashes menu filter - grid

Uncaught TypeError: Cannot read property '0' of undefined
    at FlMenuOptrUI.dropSelectedVal

const data = [
{ _id: 1, firstname: undefined, lastname: "Doe" }, // undefined value will crash filter menu
{ _id: 2, firstname: "Mary", lastname: "Jane" }
];


example
https://codesandbox.io/s/modest-mcclintock-w2skw?file=/src/App.js

5 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team June 16, 2020 11:51 AM UTC

Hi Dario, 

Greetings from Syncfusion support. 

If the first row contains undefined or null value for a column then column type needs to be defined for that since based on this initial row data only the column type will be set and based on the column type the filter menu will be rendered. This is the Grid’s default behavior. We have modified the provided sample based on this which you can find below, 

 

Please get back to us if you require any further assistance. 

Regards, 
Sujith R 


Marked as answer

DA Dario June 16, 2020 04:49 PM UTC

i see, thanks!


PK Prasanna Kumar Viswanathan Syncfusion Team June 17, 2020 09:34 AM UTC

Hi Dario, 
 
Thanks for the update. 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Prasanna Kumar N.S.V 



JP Julius Peter January 25, 2023 09:50 PM UTC

Dear Syncfusion team,

I would strongly recommend to change the grid filter standard behavior to better handle such a situation (happens probably quite often). If no type is specified on a column and the first entry is null,  default types (set for the whole grid, the installation or even in general) could be used.

 Would make life of a programmer using this component much easier ...... error messages like this are very difficult to trace and decrypt....


Regards

Julius



JC Joseph Christ Nithin Issack Syncfusion Team February 6, 2023 07:04 PM UTC

Hi Julius,


  Greetings from Syncfusion support.

  By default, in EJ2 Grid, the actions like filter, sort, etc. will be performed based on the type of the column. If the type of the column is not set, grid will automatically assign the type based on the value in the first row of the column. If the value of the first row of the column is null/undefined, the column type will not be defined. So, if null or undefined value is present in the initial row of a column and column type is not set for that column, then the type will be set as ‘null’ which causes problem.


  As you have mentioned, if we set the default type(e.g., string) for the columns when no type is specified on a column and the first-row data is null, then the grid will consider this as a string column and perform all the actions considering this as a string column. This may cause the grid to show improper results when performing the actions like filtering, sorting etc. This is the reason we have not set the default value for the column type.


Regards,

Joseph I.


Loader.
Up arrow icon