This examples shows the usage of links in ViewModel. Ext JS 6 Example: CRUD in Form, Grid and Paging in Grid Demo. Description The example shows how to use Ext.grid.View method getRowClass to style individual rows or the grid. Here we change only grid background color but it is possible to change the font weight (bold/normal), font color or other attributes. Ext.NET is an ASP.NET 5 and Core component framework. π Build wicked fast ASP.NET apps with 140+ UI components and the all new Spotless premium theme.
- Ext.js Tutorial
- Ext.js Useful Resources
- Selected Reading
This is a simple component to display data, which is a collection of record stored in Ext.data.Store in a tabular format.
Syntax
Following is a simple syntax to create grid.
Example
Following is a simple example showing grid.
The above program will produce the following result β
Grid Poperties
Collapsible β This property is to add a collapse feature to the grid. Add 'Collapsible : true' feature in grid properties to add this feature.
Sorting β This property is to add a sorting feature to the grid. Add Column property'sortable : true' in the grid to apply sorting ASC/DESC. By default, it is true. It can be made false, if you donβt want this feature to appear.
By default, sorting can be applied with property sorters : {property: 'id', direction : 'ASC'} in store. It will sort grid data based on the property provided in the sorters and the direction given, before rendering data into the grid.
Enable Column resize β Column can be resized (its width can be increased or decreased) using grid properties 'enableColumnResize: true'.
Column hideable β Add Column property 'hideable : true' in a grid to make the column appear or hide. By default, it is true. It can be made false, if you donβt want this feature to appear.
Draggable column β Add Column property 'enableColumnMove: true' is grid property with which we can move columns in a grid.
Renderer β This is the property to customize the view of grid data based on the data we get from the store.
Note β All the properties are added in the above grid example. Try them in try it editor.
In web development it is common to show data in grid format. Extjs has Grid class which is available under panel package which we need to extend in case we want to create our own grid layout. It is very easy to create our grid on web page using this class.
Letβs see an example to understand better.
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 | <head> <title>Simple Grid Example</title> <link href='extjs/resources/css/ext-all.css'rel='stylesheet'type='text/css'/> <script src='extjs/ext-all.js'type='text/javascript'></script> Ext.onReady(function(){ extend:'Ext.data.Model', fields:['firstName','lastName','age','city','country'] model:'com.code2succeed.Emp', {'firstName':'firstName1','lastName':'lastName1','age':22,'city':'New York','country':'USA'}, {'firstName':'firstName2','lastName':'lastName2','age':25,'city':'Mumbai','country':'INDIA'}, {'firstName':'firstName3','lastName':'lastName3','age':23,'city':'New Delhi','country':'INDIA'}, {'firstName':'firstName4','lastName':'lastName4','age':30,'city':'London','country':'UK'} }); Ext.create('Ext.grid.Panel',{ store:empStore, width:450, { dataIndex:'firstName' { dataIndex:'lastName' { dataIndex:'age' { dataIndex:'city' { dataIndex:'country' ] }); </head> |
Note : In this example, Extjs library is available with my project at same level of grid.html file. In case you want to add library from web or Sencha you have to use other URL or you can download it from Sencha and keep it with your project structure which is demonstrated in Start with Extjs.
Output
In above example we have used dummy json data in store. We can replace data with proxy in case we want to use URL/Service which returns json data.
2 4 6 8 10 12 | model:'com.code2succeed.Emp', type:'ajax', reader:{ root:'EmpDetail' }, }); |
Extjs Extend
We have a json file which is available under jsondata folder which contains Emp detail in json format. We have replaced dummy data with actual url which points to json file. We can pass here the actual url of controller class which can be written in Java or any other programming language.
Content of empdetail.json file.
Download Extjs
2 4 6 | {'firstName':'firstName1','lastName':'lastName1','age':22,'city':'New York','country':'USA'}, {'firstName':'firstName2','lastName':'lastName2','age':25,'city':'Mumbai','country':'INDIA'}, {'firstName':'firstName3','lastName':'lastName3','age':23,'city':'New Delhi','country':'INDIA'}, {'firstName':'firstName4','lastName':'lastName4','age':30,'city':'London','country':'UK'} |
Stay tuned for other posts related to grid layout with Java controller.