JSON
In order to import JSON (or an array of objects), simply change the data input to [{ key: value }, ... ]
.
Grid.js expects each column to have a unique id
field which matches the keys in the data
object:
Live Editor
Result
Name | Email | Phone Number |
---|---|---|
John | john@example.com | (353) 01 222 3333 |
Mark | mark@gmail.com | (01) 22 888 4444 |
tip
Grid.js tries to guess the id
of columns by camelCasing them if column ID is not defined.
E.g. Phone Number
becomes phoneNumber
Live Editor
Result
Name | Email | Phone Number |
---|---|---|
John | john@example.com | (353) 01 222 3333 |
Mark | mark@gmail.com | (01) 22 888 4444 |
You can also leave the columns
config empty if you want Grid.js to set the column names automatically:
Live Editor
Result
name | email | phoneNumber |
---|---|---|
John | john@example.com | (353) 01 222 3333 |
Mark | mark@gmail.com | (01) 22 888 4444 |
id
field accepts a function as well. If you have a complex JSON object, pass a function to id
and try to refine and format your data:
Live Editor
Result
First Name | Last Name | Email | Phone Number |
---|---|---|---|
John | Murphy | john@example.com | (353) 01 222 3333 |
Mark | Wiens | mark@gmail.com | (01) 22 888 4444 |