grid.autoFitColumns() throws an exception internally when there is no data.

Hello,

When using the autoFitColumns() function for the grid with defined columns, but with no data present in the grid, the following exception shows up in the javascript debugger:

ej2_custom2.min.js:formatted:17005 Uncaught (in promise) TypeError: Cannot read property 'querySelector' of undefined
    ( this.contentRenderer.getTable() returns undefined )
    at e.emptyRow (ej2_custom2.min.js:formatted:17005)
    at e.renderEmptyRow (ej2_custom2.min.js:formatted:17001)
    at e.dataManagerFailure (ej2_custom2.min.js:formatted:17137)
    at ej2_custom2.min.js:formatted:16937

This promise object seems to be created in the Render.prototype.refreshDataManager(args) function.

Although the columns get properly sized to fit column text and most users won't notice the error while they have no debugger active, I don't think this is supposed to happen. (I just wish to auto size the columns BEFORE I fill the grid with data)


EDIT: It looks like it was my mistake of creating my DataManager instance in the load callback, which I saved to a variable in outer scope, but load is not guaranteed to be triggered only once, so some of my checks referenced the wrong instance.
By wrapping the assignment in load in a 'if (!myvar)' condition the exception no longer appeared.


Kind regards,
Remco Beurskens

3 Replies

MS Magesh Sabapathi Syncfusion Team April 1, 2020 03:11 PM UTC

Hi Lon 
 
Query  :  Grid AutoFitcolumn() throws an exception. 
 
Before proceeding your query we need some more details about this. So please share us the following details 

  1. Full Grid code snippet.
  2. Whether you are using Remote data or local data in your sample.
  3. Clearly explain your exact issue you are facing.

Please get back to us with the following details 

Regards 
Magesh 



LH Lon Hofman April 2, 2020 10:46 AM UTC

Hello,

I found the cause (and solution) of the issue my self already. ( as explained in my EDIT of the original post )
It was a problem in my own code.

Kind regards,
Remco Beurskens


RR Rajapandi Ravi Syncfusion Team April 3, 2020 12:55 PM UTC

Hi Lon, 

We are happy to hear that you have founded the solution at your end. 

Please get back to us if you need further assistance. 


Regards, 
Rajapandi R 


Loader.
Up arrow icon