Now I can save the data from Datagrid with Checkbox, Combobox and Textbox to database.
http://www.jeasyui.com/forum/index.php?topic=5248.0My question is:
How can i populate data from database to Datagrid and automatic fill the Checkbox, Combobox and Textbox ?
Please Help Me,
Thanks.
This is My Script:
HTML
<table id="dg" class="easyui-datagrid" style="width:600px;height:250px"
url="data/datagrid_data.json"
title="Load Data" iconCls="icon-save" fitColumns="true"
idField="itemid">
<thead>
<tr>
<th field="ck" width="80" checkbox="true">Item ID</th>
<th field="itemid" width="80">Item ID</th>
<th field="productid" width="80">Product ID</th>
<th field="listprice" width="80" align="right">List Price</th>
<th field="unitcost" width="80" align="right" data-options="editor:'numberbox'">Unit Cost</th>
<th field="attr1" width="150" data-options="editor:'textbox'">Attribute</th>
<th field="statusName", data-options="align: 'center',
editor:{
type:'combobox',
options:{
valueField:'statusId',
textField:'statusName',
panelHeight:'auto',
data: [{
statusId: '',
statusName: '- Choose -'
},{
statusId: 'true',
statusName: 'Active'
},{
statusId: 'false',
statusName: 'Non Active'
}]
}
}
" width="80"><b>Status</b></th>
</tr>
</thead>
</table>
Javascript
function save() {
var rows = [];
var dg = $('#dg');
$.map(dg.datagrid('getChecked'), function(row){
var index = dg.datagrid('getRowIndex', row);
var editors = dg.datagrid('getEditors', index);
if (editors.length){
rows.push({
itemid: row.itemid,
unitcost: $(editors[0].target).numberbox('getValue'),
attr1: $(editors[1].target).textbox('getValue'),
statusName: $(editors[2].target).combobox('getValue')
});
}
});
$.ajax({
url:'./data.php',
type: 'POST',
data: {data: JSON.stringify(rows)},
cache: false
});
}
PHP (getdata.php)
$conn = mysqli_connect($host, $user, $pass, $db);
mysqli_query($conn, "SELECT * FROM tbl_test");