Bootstrap-table template
by joeycakes
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.7.0/bootstrap-table.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.7.0/bootstrap-table.min.js"></script>
<!-- The table -->
<table id="table">
<thead>
<tr>
<th data-field="github.name" data-sortable="true">Name</th>
<th data-field="github.stargazers_count" data-sortable="true">Stars</th>
<th data-field="github.forks_count" data-sortable="true">Forks</th>
<th data-field="github.description" data-sortable="true">Description</th>
</tr>
</thead>
</table>
JavaScript
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.1.0
*/
(function ($) {
'use strict';
var flatJSON = function (el, data) {
if (el.options.flat) {
el.options.data = sd.flatHelper(data);
}
if (el.options.sidePagination === 'server') {
el.data = el.options.data;
}
};
$.extend($.fn.bootstrapTable.defaults, {
flat: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initData = BootstrapTable.prototype.initData,
_init = BootstrapTable.prototype.init,
_initTable = BootstrapTable.prototype.initTable;
BootstrapTable.prototype.initData = function (data) {
flatJSON(this, data === undefined ? this.options.data : data);
_initData.apply(this, Array.prototype.slice.apply(arguments));
};
BootstrapTable.prototype.init = function () {
flatJSON(this, this.options.data);
_init.apply(this, Array.prototype.slice.apply(arguments));
};
BootstrapTable.prototype.initTable = function () {
flatJSON(this, this.options.data);
_initTable.apply(this, Array.prototype.slice.apply(arguments));
};
//Main functions
var sd = {
flat: function (element) {
var result = {};
function recurse(cur, prop) {
if (Object(cur) !== cur) {
result[prop] = cur;
} else if ($.isArray(cur)) {
for (var i = 0, l = cur.length; i < l; i++) {
recurse(cur[i], prop ? prop + "." + i : "" + i);
if (l == 0) {
result[prop] = [];
}
}
} else {
var isEmpty = true;
for (var p in cur) {
isEmpty = false;
recurse(cur[p], prop ? prop + "." + p : p);
...