Error loading remote data into grid

Hi,

I am tying to dynamically generate a grid  with stacked headers. Unfortunately, I am getting an error that I cannot understand. Here are things to know :
  1. The data is fetched from an external Firebase DB (which means the data is created or fetched after runtime).
  2. The typescript variables (that are also used in the HTML template) depend on the fetched data, and therefore are also given a value after runtime.

Scenarios I tried (see code snippet below) :

1. Rendering the grid without the stacked headers portion (commenting it).
  • Result : Success. The gris renders properly without any error. However I still need the stacked headers section, so I need to find a fix. As soon as I un-comment this section, I get an error saying "e.isForeignColumn is not a function"
2. Simulate an already initialized column model instead of waiting for data to create it.
  • Instead of waiting for the fetched data to create my "month1Columns" column model, I tried to initialize it within the app with dummy values to see if the fact that the data is fetched remotely is the source of the problem and it turns out I do not get any error when initializing the column model within the app as seen here. However, I still need to fetch my data from the DB to generate the column models, so this is not a solution for me :
public month1Columns: ColumnModel[] = [{
customAttributes: {class: 'dateDayRow'},
field: '4',
headerText: '1',
width: '40',
textAlign: 'Center',
maxWidth: '60'
}];

Am I doing it correctly?

Here is a link to a minimal stackblitz project to demonstrate the issue :

Regards,

<ejs-grid [dataSource]='this.employeesArray' gridLines='Both'>
  <e-columns>

    <e-column field='busDate'           headerText='BUS DATE' textAlign="Center" [width]="90" [maxWidth]="90">e-column>
    <e-column field='badge'               headerText='BADGE'       textAlign="Center" [width]="90" [maxWidth]="90">e-column>
    <e-column field='fullName'       headerText='NOM'            textAlign="Center" [width]="90" [maxWidth]="90">e-column>
    <e-column field='vacationQuota' headerText=''                     textAlign="Center" [width]="40" [maxWidth]="90">e-column>

    ## ADDING THIS STACKED HEADER SECTION GIVES AN ERROR, EVEN IF I ONLY PUT 1 INSTEAD OF THE 12. COMMENTING IS MAKES THE GRID WORK, BUT IS MISSING THE DESIRED DATA     
    <e-column headerText="{{this.months[0]}}"  [columns]="this.month1Columns">e-column>
    <e-column headerText="{{this.months[1]}}"  [columns]="this.month2Columns">e-column>
    <e-column headerText="{{this.months[2]}}"  [columns]="this.month3Columns">e-column>
    <e-column headerText="{{this.months[3]}}"  [columns]="this.month4Columns">e-column>
    <e-column headerText="{{this.months[4]}}"  [columns]="this.month5Columns">e-column>
    <e-column headerText="{{this.months[5]}}"  [columns]="this.month6Columns">e-column>
    <e-column headerText="{{this.months[6]}}"  [columns]="this.month7Columns">e-column>
    <e-column headerText="{{this.months[7]}}"  [columns]="this.month8Columns">e-column>
    <e-column headerText="{{this.months[8]}}"  [columns]="this.month9Columns">e-column>
    <e-column headerText="{{this.months[9]}}"  [columns]="this.month10Columns">e-column>
    <e-column headerText="{{this.months[10]}}" [columns]="this.month11Columns">e-column>
    <e-column headerText="{{this.months[11]}}" [columns]="this.month12Columns">e-column>

  e-columns>
ejs-grid>


5 Replies 1 reply marked as answer

MF Mohammed Farook J Syncfusion Team June 15, 2020 08:43 AM UTC

Hi Remy, 
 
Thanks for contacting Syncfusion support. 
 
We have validated the given sample and we have found that, for generating the dynamic column model is take some delay. So you are getting  that mentioned error because the column model is not generate properly. So we have suggesting to use, the following code to resolve this issue.  
 
 
ngOnInit(): void { 
    this.isCol =false; 
 
    // Get Employees data 
    this.afs.collection('/BusinessUnits/Ndm7YfzHa6WtMYNWnt5D/Departments/sLPxRdmqfxkyPCrKaMS6/Years/CrqKGMz1xOGusPA4ndPS/Employees', ref => ref.orderBy('busDate')).valueChanges().subscribe(result => { 
 
      // Store data in variable 
      this.employeesArray = result; 
      this.employeesArray.map(employee => { 
 
        // Convert timestamp to date 
        if (employee.busDate) { 
          employee.busDate = formatDate(employee.busDate.toDate(), 'yyyy-MM-dd', 'FR-fr'); 
        } 
 
        // For each item, dynamically push to arrays 
        for (let i = 1; i <= Object.keys(employee.arrayOfWeeks).length; i++) { 
 
          // Dynamically create "months" array everytime a new month is encountered 
          if (this.months.indexOf(formatDate(employee.arrayOfWeeks['week' + i]['date'].toDate(), 'MMMM yyyy', 'FR-fr').toString()) < 0) { 
            if(this.months.length >0){ 
              // push the new column here 
              this.newCol.push({headerText:'month' + this.months.length + 'Columns', columns: this['month' + this.months.length + 'Columns'] }) 
 
            } 
            this.months.push(formatDate(employee.arrayOfWeeks['week' + i]['date'].toDate(), 'MMMM yyyy', 'FR-fr').toString()); 
          } 
         // 
          // Dynamically create column models 
          this['month' + this.months.length + 'Columns'].push({ 
            field: `arrayOfWeeks.week${i}.displayedText`, 
            headerText: formatDate(employee.arrayOfWeeks['week' + i]['date'].toDate(), 'd', 'FR-fr').toString(), 
            width: '40', 
            textAlign: 'Center', 
            maxWidth: '60' 
          });   
 
        } 
 
 
      }); 
      
    (this.grid as any).columns =   (this.grid as any).columns.concat(this.newCol); // merge the new column into grid column 
     (this.grid as any).refreshColumns(); // need to call refreshColumns for add new columns 
 
    }); 
 
 
           
         
 
In the above code example we have pushed new column in your data iteration function.  We have merged the Grid column and your dynamic columns once your data iteration completed. We need to call ‘refreshColumns()’  method of update the column model into Grid.  Please find the sample for your reference. 
 
 
 
Please find the documentation for your reference. 
 
 
Regards, 
J Mohammed Farook  
 
 


Marked as answer

RE Remy June 15, 2020 04:10 PM UTC

Hi Mohammed,

Thank you very much for your support.

With some fine-tuning I was able to get it to work. However, as the data is loaded after runtime, my queryCellInfo method is struggling to find data at runtime and throws tons of errors. Is there a way I can fix this?

You will find a working demo here :
https://stackblitz.com/edit/angular-ivy-s1yhzx

Regards,
Remy


TS Thiyagu Subramani Syncfusion Team June 16, 2020 04:27 AM UTC

Hi Remy, 

Thanks for your update. 

In your reported code you are used args.data['arrayOfWeeks']['week' + (args.column.index - 4)] in queryCellInfo but its returns the undefined value before column index as 4. 

For example when using index as 0 its returns the week-4 ([‘week’ + (0-4)]).  Please refer to the below image. 

 
So we suggest to use below code to overcome the script error in queryCellInfo event. 

queryCellInfo(args: QueryCellInfoEventArgs) { 
    // CELL STYLING DEPENDING ON VACACTION/ABSENCE TYPE 
    for (const cellClass of this.vacationType) { 
      if (args.data['arrayOfWeeks']['week' + (args.column.index - 4)] != undefined) {  
        . . . . . . . .  
    } 
    // CELL TOOLTIP 
    if (args.data['arrayOfWeeks']['week' + (args.column.index - 4)] != undefined) { 
. . . . . . . . . . 
  } 


Please refer to the below modified sample. 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S. 



RE Remy June 16, 2020 11:57 PM UTC

Hi Thiyagu,

Thank you, you were absolutely right. I completely missed that. Thanks again for your quick support.

Regards,


TS Thiyagu Subramani Syncfusion Team June 17, 2020 04:46 AM UTC

Hi Remy 

Thanks for your update. 

We're glad to hear that your problem has been resolved. 

Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S 


Loader.
Up arrow icon