The best jQuery EasyUI Data Grid - Creating a Custom View Tutorial In 2024, In this tutorial you can learn Download jQuery EasyUI examples,
Under different circumstances, you may need a data grid (datagrid) using more flexible layout. For users, the card view (Card View) is a good choice. This tool can quickly acquire and display data in data grid (datagrid) in. In the data grid (datagrid) head, you can just by clicking on a column header to sort the data. This tutorial will show you how to create a custom card view (Card View).
Inherited from Data Grid (datagrid) default view, create a custom view is a good method. We are going to create a card view (Card View) to display some of the information for each row.
var cardview = $.extend({}, $.fn.datagrid.defaults.view, { renderRow: function(target, fields, frozen, rowIndex, rowData){ var cc = []; cc.push('<td colspan=' + fields.length + ' style="padding:10px 5px;border:0;">'); if (!frozen){ var aa = rowData.itemid.split('-'); var img = 'shirt' + aa[1] + '.gif'; cc.push('<img src="images/' + img + '" style="width:150px;float:left">'); cc.push('<div style="float:left;margin-left:20px;">'); for(var i=0; i<fields.length; i++){ var copts = $(target).datagrid('getColumnOption', fields[i]); cc.push('<p><span class="c-label">' + copts.title + ':</span> ' + rowData[fields[i]] + '</p>'); } cc.push('</div>'); } cc.push('</td>'); return cc.join(''); } });
Now we use a view to create a data grid (datagrid).
<table id="tt" style="width:500px;height:400px" title="DataGrid - CardView" singleSelect="true" fitColumns="true" remoteSort="false" url="datagrid8_getdata.php" pagination="true" sortOrder="desc" sortName="itemid"> <thead> <tr> <th field="itemid" width="80" sortable="true">Item ID</th> <th field="listprice" width="80" sortable="true">List Price</th> <th field="unitcost" width="80" sortable="true">Unit Cost</th> <th field="attr1" width="150" sortable="true">Attribute</th> <th field="status" width="60" sortable="true">Status</th> </tr> </thead> </table>
$ ( '# Tt'). Datagrid ({ view: cardview });
Note that we set the view properties, and it is our view card.