Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap table data diffing #10

Merged
merged 12 commits into from Jan 17, 2017
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -42,6 +42,7 @@
"jqGrid": "^5.1.1",
"jquery": "2.2.1",
"jqwidgets-framework": "^4.4.0",
"lodash": "^4.17.4",
"moment": "2.16.0",
"perfect-scrollbar": "^0.6.16",
"stats.js": "^0.17.0",
Expand Down
37 changes: 30 additions & 7 deletions src/components/bootstrap-table/bootstrap-table.html
Expand Up @@ -3,10 +3,10 @@
text-decoration: underline;
}
.demo-wrap{
margin-bottom:1em;
margin-bottom:8em;
}
.table-wrap{
max-width: 450px;
max-width: 1026px;
height: 350px;
display:inline-block;
margin-bottom:5em;
Expand All @@ -28,6 +28,7 @@ <h2>{{demoVm.title}}</h2>
</div>



</div>


Expand Down Expand Up @@ -88,12 +89,34 @@ <h2>{{demoVm.title}}</h2>
vm = can.viewModel('.demo');


var mockData = getMockData(20,20000);
var startIndex = 0,
refreshIntervalDuration = 10000,
// refreshIntervalDuration = 10000,
cols = 20, //this is not used with real data
rows = 20000,
maxRows = 40000,
// maxRows = 50000,
mockData = getMockData(cols,rows, startIndex),
demoVm = new DemoVM({
title: 'Demo for bootstrap-table',
tableData: mockData
}),
refreshInterval = setInterval(() => {
// debugger;
startIndex += rows;
if(startIndex >= maxRows){
clearInterval(refreshInterval);
return;
}
let newData = getMockData(cols, rows, startIndex),
tableData = demoVm.attr("tableData").attr();

tableData.rows.push.apply(tableData.rows, newData.rows);
demoVm.attr("tableData", tableData);
}, refreshIntervalDuration);

vm.attr({
demoVm: new DemoVM({
title: 'Demo for bootstrap-table',
tableData: mockData
})
demoVm: demoVm
});

</script>
Expand Down
45 changes: 42 additions & 3 deletions src/components/bootstrap-table/bootstrap-table.js
Expand Up @@ -8,10 +8,11 @@ import 'bootstrap-table/dist/bootstrap-table.min.css!';
import './extensions/bootstrap-table-fixed-columns/bootstrap-table-fixed-columns.css!';
import 'bootstrap/dist/js/bootstrap.min';
import 'bootstrap-table/src/bootstrap-table';
import 'bootstrap-table/src/extensions/multiple-sort/bootstrap-table-multiple-sort'
import './extensions/bootstrap-table-multiple-sort/';
import './extensions/bootstrap-table-fixed-columns/';
import './extensions/bootstrap-table-perfect-scrollbar/';
import './extensions/bootstrap-table-pagination-events/';
import './extensions/bootstrap-table-refresh-data/';


//We'd probably want to implement our own filter control. This one is pretty slow.
Expand All @@ -22,6 +23,18 @@ export default Component.extend({
viewModel: ViewModel,
template,
events:{

//---- CONTROLLER PROPERTIES ----//

//flag to know whether or not to manually insert/remove items
// Initially false because the initialization of the comoponent
// will insert all items in the beginning
manageDataOnChange: false,

//---- END CONTROLLER PROPERTIES ----//


//---- INITIALIZATION ----//
"inserted": function($el, ev){
this.$el = $(this.element);
this.$table = this.$el.find("table");
Expand All @@ -30,6 +43,9 @@ export default Component.extend({
performanceMap && performanceMap.setRenderStartTime();
this.initBootstrapTable();
performanceMap && performanceMap.setRenderEndTime();

//set flag for managing incoming data
this.manageDataOnChange = true;
},

initBootstrapTable(){
Expand All @@ -43,6 +59,7 @@ export default Component.extend({
pagination: true,
height: this.$el.height(),
search: true,
pageSize: 100,

//http://issues.wenzhixin.net.cn/bootstrap-table/extensions/fixed-columns.html
fixedColumns: true,
Expand All @@ -51,6 +68,9 @@ export default Component.extend({
perfectScrollbar: true,

showMultiSort: true,
sortPriority: [{sortName: 1, sortOrder: 'asc'}, {sortName: 3, sortOrder: 'desc'}],

diffProp: 3,

onPageChange: function(num, size){
self.onPageChange(this, num, size);
Expand All @@ -67,7 +87,10 @@ export default Component.extend({
}
});
},

//---- END INITIALIZATION ----//


//---- EVENTS ----//
onPageChangeBefore(tablePlugin, num, size){
var performanceMap = this.viewModel.attr("performanceMap");
performanceMap && performanceMap.setLastPageStart();
Expand All @@ -83,9 +106,25 @@ export default Component.extend({
performanceMap && performanceMap.setLastSortEnd();
},

onSort(tablePlugin, name, order){
onSort(tablePlugin, sortPrioirty){
var performanceMap = this.viewModel.attr("performanceMap");
performanceMap && performanceMap.setLastSortStart();
},
//---- END EVENTS ----//


//---- DATA CHANGING ----//
"{viewModel} tableRows": function(vm, ev, newVal, oldVal){
if(this.manageDataOnChange){
var newRows = newVal.attr ? newVal.attr() : newVal;
this.onDataChanged(newRows, oldVal);
}
},
onDataChanged(newVal, oldVal){
this.$table.bootstrapTable("refreshData", newVal);
}
//---- END DATA CHANGING ----//


}
});
9 changes: 8 additions & 1 deletion src/components/bootstrap-table/bootstrap-table.less
@@ -1,4 +1,11 @@
bootstrap-table {
display: block;
height: 100%;
height: 100%;

th {
background: #E6E6E9 url(./images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;
}
.table-hover > tbody > tr:hover, .bootstrap-table .table-hover > tbody > tr.hover > td {
background-color: #CCF4FF;
}
}
4 changes: 2 additions & 2 deletions src/components/bootstrap-table/bootstrap-table.viewmodel.js
Expand Up @@ -14,7 +14,6 @@ export default Map.extend({
var objOut = {
id: i,
field: i,
title: "header-" + i,
sortable: true,
originalData: h,
width: i == 0 ? 193 : 110
Expand All @@ -24,6 +23,7 @@ export default Map.extend({
var n = h.attr("name");
if(n){
objOut.title=n;
objOut.titleTooltip=n;
}

switch (h.type) {
Expand All @@ -35,7 +35,7 @@ export default Map.extend({
break;
case 'KPI':
objOut.formatter = function(value) {
return value ? value.toFixed(2) : value;
return value ? value.toLocaleString() : value;
};
break;
}
Expand Down