Here we mainly introduce two functions: aocolumndefs and createdrow.
The usage of datatables is very simple. You can check the information and directly use the code:
VaR T;
T = $ ("# accounttbl"). datatable ({
Searching: True,
Processing: True,
DOM: "<'row' <'col-sm-12 'tr> \ n \ t <'row' <'col-sm-12 col-md-5 'I> <'col-sm-12 col-md-7 datatables_pager 'lp> ",
Language :{
"Info": "display _ start _ to _ end _ total _ records ",
"Infoempty": "display records from 0 to 0 of 0 ",
"Lengthmenu": "_ menu _ records displayed on each page ",
"Emptytable": "No query records ",
"Loadingrecords": "loading ...",
"Zerorecords": "No query records ",
},
// Aocolumndefs :[
// {"Sclass": "col_class", "atargets": [0] },{ "sclass": "cos_class", "atargets": [1]}],
Createdrow: function (row, Data, index ){
If (index % 2 = 0 ){
$ ('Td ', row).css ('font-westight', "bold" 2.16.css ("color", "# c43ff6 ");
}
},
Buttons: ["print", "copyhtml5", "excelhtml5", "csvhtml5", "pdfhtml5"],
Select: True,
Rowid: 'id ',
Serverside: True,
Ajax :{
"Url ":'',
},
Columns :[{
Data: "ID ",
"Orderable": True, "width": "50px"
},
],
})
1. aocolumndefs:
This function modifies the Column Display. {"sclass": "col_class", "atargets": [0]}, "atargets" indicates the first column from left to right, the second column is [1]. This col_class needs to be defined on the front end.
<Style>
. Col_class {
Color: # ff7e29;
}
. Cos_class {
Color: #2a1cf6;
}
</Style>
2,Createdrow:
This function is used to modify the row display. createdrow: function (row, Data, index) {}, the three parameters "row" represent the row, and "data" represent the field you passed in, this means that you can filter and display fields based on their content,
Index is the index value of the row.
Line color display:
If (index % 2 = 0 ){
$ ('Td ', row).css ('font-westight', "bold" 2.16.css ("color", "# c43ff6 ");
}
Display by ID:
if ( data[‘id] %2 == 0 ) {
$(‘td‘, row).css(‘font-weight‘,"bold").css("color","#c43ff6");
}
PS: If you want to modify the length of the TD tag, you can restrict it in columns.
columns: [{
data: "id",
"orderable": true,"width":"50px"
},
],
Datatbles modify the display style (modify the row and column background color, Font, and line color)