Hi,
I have a use case where my data comes like this:
{
'date':'10-10-2017', 'values':{'column':'columnName1','value':'value1','id':12},{'column':'columnName2','value':'value2','id':34},
'date':'11-10-2017', 'values':{'column':'columnName1','value':'value1','id':56},{'column':'columnName2','value':'value2','id':78}
}
Here, the ‘date’ field becomes the row headers and the ‘column’ field is the one used to define the columns in the table. Both these fields are dynamic, that being a user can select a list of dates and a list of column names to show from a list and the table should reflect it. Currently, I’m extracting the ‘date’ and ‘column’ fields as two different lists to feed them to the table configuration as the headers and columns lists but for the values to show in the table I cannot seem to be able to use a list of lists of objects because I cannot select the value to show from the object itself. I would like to be able to use as data at least this:
{
{'column':'columnName1','value':'value1','id':12},{'column':'columnName2','value':'value2','id':34},
{'column':'columnName1','value':'value1','id':56},{'column':'columnName2','value':'value2','id':78}
}
And here tell the table to use ‘value’ as the field to show. Otherwise, I would need to extract the field ‘value’ from the objects and create a view of my list of lists only with it and then match the values modified in the table based on their index to update the source list. All that to be able to send the updated values alongside their ids to the server for update.
For what I’ve seen in the documentation, it is possible to use a list of objects where each object is a row to show in the table and you can configure which field to use for each column. But I haven’t seem any way to do what I need to do.
Thanks.
Hi @juanma.cvega
I am not sure if I fully understand, but here’s a demo that may help http://jsfiddle.net/jet5k1su/
Let me know if that’s not what you were thinking about.
Hi @aleksandra_budnik
thanks for your answer. Sorry I couldn’t explain myself properly. I just realised even the json example was a bit wrong as I didn’t enclosed the elements in []
to show it was an array.
What you linked shows the part I mentioned about being able to use a list of objects where each object is a row. But as you can see in your own example, you are only using the objects in the first list to show the table. There, the first object of the list represents the first row and the second object the second row.
What I would need would be to be able to pass both lists of elements as data and then, out of each object, only use the field ‘value’ as the cell value.
For example, if I pass as data:
{[
[1,2],
[3,4]
]}
That would show a table where 1 and 2 would be in the first row and 3 and 4 in the second. But if I pass:
[
[{'value':1},{'value':2}],
[{'value':3},{'value':4}]
]
That doesn’t work as I cannot tell the table to use ‘value’ as the field with the data for the cell. In my use case, the reason I need this is to be able to keep the data structure where I know for each value what its id is so when it changes I can send to the server both the value changed and its id. So the example above would look like:
[
[{'value':1,'id':1234},{'value':2,'id':4567}],
[{'value':3,'id':7890},{'value':4,'id':3456}]
]
I hope it’s more clear know.
Thanks.
Here http://jsfiddle.net/eer86wxb/ is a basic example I have made some time ago. It uses the same data structure. However, as you can see you would need to parse it first to use it.
I see. That’s similar to what I had to do in my use case. The problem with that is that we are forced to keep a view of the real data to match changes against it using the row and column indexes of the cell modified. Not difficult to do but it’d be nice to have this built-in.
Anyway, thanks for the answer.
You’re welcome @juanma.cvega
I hope that this will be available in the future. Thank you for the suggestion.