Permalink
Browse files

fix: 优化前端新增删除数据时总条数的显示

  • Loading branch information...
liuyk
liuyk committed Dec 28, 2016
1 parent d14c3f2 commit 880e77e009f55e33b179908706f92a73b5217ed9
Showing with 29 additions and 12 deletions.
  1. +2 −2 js/dataTable/data.js
  2. +1 −0 js/dataTable/indexDataTable.js
  3. +26 −9 js/dataTable/page.js
  4. +0 −1 js/dataTable/row-util.js
View
@@ -43,7 +43,7 @@ const setData = function (data,options) {
if (newIndex != this.pageIndex()) {
this.setCurrentPage(newIndex, true);
this.totalPages(newTotalPages)
this.totalRow(newTotalRow)
this.totalRow(newTotalRow + this.newCount)
return;
}
else {
@@ -59,7 +59,7 @@ const setData = function (data,options) {
this.totalPages(data.totalPages)
}
if(data.totalRow || data.totalRow === 0){
this.totalRow(data.totalRow)
this.totalRow(data.totalRow + this.newCount)
}
} else {
select = data.select||(!unSelect?[0]:[]);
@@ -217,6 +217,7 @@ class DataTable{
}else{
this.ns = '';
}
this.newCount = 0;
View
@@ -57,21 +57,36 @@ const updatePages = function (pages) {
if (!r.id)
r.id = Row.getRandomRowId()
if (r.status == Row.STATUS.DELETE) {
var row = page.getRowByRowId(r.id)
if(row){
// 针对后台不传回总行数的情况下更新总行数
var oldTotalRow = this.totalRow();
var newTotalRow = oldTotalRow - 1;
this.totalRow(newTotalRow);
if(row.status == Row.STATUS.NEW){
this.newCount -= 1;
if(this.newCount < 0)
this.newCount = 0;
}
}
this.removeRowByRowId(r.id)
page.removeRowByRowId(r.id)
// 针对后台不传回总行数的情况下更新总行数
var oldTotalRow = this.totalRow();
var newTotalRow = oldTotalRow - 1;
this.totalRow(newTotalRow);
} else {
row = page.getRowByRowId(r.id)
if (row) {
page.updateRow(row, r);
if(row.status == Row.STATUS.NEW){
// 针对后台不传回总行数的情况下更新总行数
var oldTotalRow = this.totalRow();
var newTotalRow = oldTotalRow + 1;
this.totalRow(newTotalRow);
// if(row.status == Row.STATUS.NEW){
// // 针对后台不传回总行数的情况下更新总行数
// var oldTotalRow = this.totalRow();
// var newTotalRow = oldTotalRow + 1;
// this.totalRow(newTotalRow);
// }
if(row.status == Row.STATUS.NEW && r.status != Row.STATUS.NEW){
this.newCount -= 1;
if(this.newCount < 0)
this.newCount = 0;
}
row.status = Row.STATUS.NORMAL
if(r.status == Row.STATUS.NEW){
@@ -83,6 +98,8 @@ const updatePages = function (pages) {
page.rows.push(r);
if(r.status != Row.STATUS.NEW){
r.status = Row.STATUS.NORMAL;
}else{
this.newCount += 1;
}
// 针对后台不传回总行数的情况下更新总行数
var oldTotalRow = this.totalRow();
View
@@ -133,7 +133,6 @@ const _getField = function (rowObj, fieldName) {
var rat = _findField(rowObj, fieldName);
if (!rat) {
var msg = 'field:' + fieldName + ' not exist in dataTable:' + rowObj.parent.root.id + '!'
console.error(msg);
throw new Error(msg);
}
return rat;

0 comments on commit 880e77e

Please sign in to comment.