IgniteUI DataSorce or igDataSource is a component of the Ignite UI framework. It binds various UI components to the data of the various forms like JSON, XML etc.
Step 1: Creating the Data
Let us say you have a JSON data as shown in the listing below:
Data could be in the following form,
- JSON object
In real projects data will be pulled in the system from the remote services. Remote service could be WCF, REST or Web API.
Step 2: Create the render function
Let us say we have a requirement to render the data in a HTML table. We have created a HTML table as shown in the listing below:
Next to render the table we need to,
- Create template using the jQuery template. In the template we are using the column name from the key of the JSON data.
- Attach the template to HTML table
- Create data view on the data source and attach to the HTML table
Render table function can be written as shown in the listing below:
Step 3: Create the igDataSource
In the last step we need to create the data source from the JSON data. In Ignite UI, igDataSource connects the data and the view. igDataSource can be created as shown the listing below:
We need to set the value for the datasource and the callback properties. Datasource property is set to the JOSN array and callback property is set to the renderTable function. In the renderTable function we are creating the template and rendering the table.
Running the application
On running the application, we will get JSON data rendered in the HTML table using the igDataSource. Rendered table should look as shown in the image below:
I hope you find this post useful. Thanks for reading.