ghiscoding/aurelia-slickgrid

Build Table Dynamically

Closed this issue · 4 comments

Is it possible to build a table dynamically using Aurelia-slickgrid framework.
I have a REST controller, that returns number of columns, column header names, and each row data
Basically definition of a table has to be reloaded every time we open a view where the table is present.
Where N is the number of coloumns and M is the number of rows
{
"noOfColumns":"N",
"headers":["column1","column2","column3","coloumn4",.....,ColumnN],
"data":{
"row0" : ["v1","v2","v3",......,"vN"],
"row1" : ["v1","v2","v3",......,"vN"],
"row2" : ["v1","v2","v3",......,"vN"],
"row3" : ["v1","v2","v3",......,"vN"],
.
.
.
"rowM" : ["v1","v2","v3",......,"vN"],
}
}

This requirement comes in as I have a pivot query which doesn't return same number of columns each time the query is executed. I don't want to return the data as rows and then translate in my server side code I have huge amount of data.

First of all, dealing with dynamic tables is not the best and is a bit risky as you might see some weird behaviors because you are setting fixed/static column definitions.

However, there maybe 2 ways of dealing with this

  1. You can add column definition dynamically, you can see that in Example 3 and Example 12, the last button adds dynamically (in that demo it recopies the Title column dynamically).
  2. In our project we hide certain columns depending on the user's role, and for that we use an if.bind on the container where you have the <aurelia-slickgrid> to only build the grid only after we pulled the user's role. To do that, we have a prepareGrid that has all the possible column definitions, and then after we get the user's role (in async), we then remove/filter out the column that the user doesn't have access.

It is better to use the number 2) if you can as number 1) might work but is harder to troubleshoot because of it's dynamic nature.

Side Note: Please next time use the GitHug issue template when opening an issue, it helps in troubleshooting, analyzing and triage. Thank you

I understand the risk of dealing with dynamic tables. But all my columns are of string data type and I'm not intending to do anything on the data except present them in the dynamic tables. This just basic reports for our product which we want to integrate in the product UI itself as out of box reports.

I reviewed the code. I think I got on what needs to be done. Thanks for your quick information.

Ok great, if you like the lib you can also up vote ⭐️ if you haven't already. Thanks 😺