Fixed table header
Column width can be adjusted
Click the column header to sort
Double-click the cell to edit
Can bind data source
Look at the effect:
HTML - Template code:
{Name}
|
< td editable='true'>
{Gender}
{Age}
|
{Address}
|
jsascript code:
//Test data
var dataJsonStr='{tablename:"",rows:[{"Name":"Cao Cao","Gender":"Male","Age":"51","Address":"Xuchang"},{"Name" :"Zhuge Liang","Gender":"Male","Age":"40","Address":"Nanyang"},{"Name":"Zhou Yu","Gender":"Male","Age" :"40","Address":"Jiangdong"},{"Name":"Da Qiao","Gender":"Female","Age":"30","Address":"Jiangdong"},{ "Name": "Xiao Qiao", "Gender": "Female", "Age": "28", "Address": "Jiangdong"}, {"Name": "Cao Cao", "Gender": "Male" ,"Age":"51","Address":"Xuchang"},{"Name":"Zhuge Liang","Gender":"Male","Age":"40","Address":"Nanyang" },{"Name":"Zhou Yu","Gender":"Male","Age":"40","Address":"Jiangdong"},{"Name":"Da Qiao","Gender": "Female", "Age": "30", "Address": "Jiangdong"}, {"Name": "Xiao Qiao", "Gender": "Female", "Age": "28", "Address" :"江东"}]}';
//Clear data
$('#test').DataGridClear();
//Set row style
$('#test') .DataGridSetItemClass("tr1","tr2","trhover");
//Bind data and set the width and height
$('#test').DataGrid("100%",200,dataJsonStr ; 🎜>
Copy code
The code is as follows:
TableBody.wrap('
');
TableHead.wrap("
");
var TableBodyArea=MyTable.find('.TableBodyArea');
var TableHeadArea=MyTable.find('.TableHeadArea ');
TableBody.data('TableBodyArea',TableBodyArea);
TableBody.data('TableHeadArea',TableHeadArea);
The red highlighted TableBody in the above generation is the table The main body, TableHead is the table header
2. Create the table header
Copy the code
The code is as follows:
Copy code
The code is as follows: