Recently contacted a NB plug-in, Bootstrap table did not do the front end of the impression of the table is only stuck in the HTML table tag that set, after using Bootstrap table has to say really cow X.
Construction Method
1, HTML
<div class= "Btn-group hidden-xs" id= "Exampletableeventstoolbar" >//define a series of toolbars ... </div> <table data-toggle= "table" Data-url= "${ctxadmin}/user/userdata?orgid=${orgid}"//table data source, JSON format data-pagination= "true" Whether pagination data-show-search= "true" or not displays the search box feature data-show-columns= "true"//Show Columns Function button data-icon-size= "outline" data-
Mobile-responsive= "true" data-height= "id=" tablelist data-side-pagination= "Server"//support page paging, default is Client> <thead> <tr> <th data-field= "user_id" >ID</th> <th data-field= "username" da Ta-formatter= "usernameformatter"//columns option See official website explanation data-events= "usernameevents" > Username </th> <th data-field= "Real_name" > real name </th> <th data-field= "Tel_num" > Landline </th> <th data-field= "mobile" > Mobile </th> <th data-field= "user_type" > User type </th> <th data-field= "Operation" Data-for Matter= "Actionformatter" Data-events= "actionevents" > Operations </th> </tr> </thead> </table>
2, JS Construction:
(function () {
$ (' #tablelist '). bootstraptable ({
URL: "${ctxadmin}/user/userdata?orgid=${orgid}",
Search:true, //whether to display the search box function
pagination:true, //Whether paging
showrefresh:true,//whether to display the Refresh function
Showtoggle: True,
showcolumns:true,
iconsize: ' Outline ',
//toolbar: ' #exampleTableEventsToolbar ', A toolbar that can be displayed above the table,
icons: {
refresh: ' Glyphicon-repeat ',
Toggle: ' Glyphicon-list-alt
', Columns: ' Glyphicon-list '
}
});
A combination of the official online display of table Options,column Options,events,methods can accomplish many functions. The data-formatter above, data-events is the option in column options.
Data-formatter and Data-events
To achieve the following effect, use the above two option, a definition format, a definition of the click of the operation.
Directly on the JS code
Value: The current display value of the Collumn,
//row: The entire row of data, object, can be passed. Get
//table-action-format
function Actionformatter (value, row, Index) {return
' <a class= ' mod ' > Modify </a> ' + ' <a class= ' delete ' > Delete </a> ';
}
Table -action-event
window.actionevents = {
' click. MoD ': function (E, value, row, index) {
//modify Operation
},
' click. Delete ': function (E, value, row, index) {
//delete operation
}
}
Server Paging/client paging conversion, table refresh
Bootstrap default is client paging, available through HTML tags
Data-side-pagination: "Client"
Or JS in the
Sidepagination: ' Server '
Specified. Note that the JSON data format is not the same in either of these two backgrounds .
Client: Normal JSON array format [{},{},{}]
Server: {"Total": 0, "Rows": [] The total represents the number of data bars for the query, and subsequent rows refers to the amount of data displayed on the current page.
Things need to change according to the circumstances of the paging way, it is necessary to use the methods
' Refreshoptions '//Set update options
' Refresh '//Set the URL for the update, query (back to pass parameters)
$ ("#tablelist"). Bootstraptable (' Refreshoptions ', {
sidepagination: ' Client ' //change to clients page
});
$ ("#tablelist"). Bootstraptable (' Refresh ', {
URL: ' ${ctxadmin}/user/getsearchuserinfo ',//Reset data source
query: { Username: $ (' #sea-username '). Val (), Realname: $ ("#sea-realname"). Val (), Mobile: $ ("#sea-mobile"). Val ()}//the parameters to the background
});