Skip to content

Commit

Permalink
Fix edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Rousseau committed Oct 17, 2016
1 parent 13dfedd commit 53f5f5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class BootstrapTable extends Component {
}
});

if (sectionKey) {
if (!Array.isArray(this.state.data)) {
data = this.state.data[sectionKey];
} else {
data = this.state.data;
Expand Down
36 changes: 11 additions & 25 deletions src/store/TableDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,40 +157,26 @@ export class TableDataStore {
return this;
}

edit(newVal, rowIndex, fieldName) {
edit(newVal, rowIndex, fieldName, sectionKey) {
const currentDisplayData = this.getCurrentDisplayData();
let rowKeyCache;
if (!this.enablePagination) {
currentDisplayData[rowIndex][fieldName] = newVal;
rowKeyCache = currentDisplayData[rowIndex][this.keyField];
let offset;

if (!Array.isArray(this.data)) {
offset = currentDisplayData[sectionKey];
} else {
currentDisplayData[this.pageObj.start + rowIndex][fieldName] = newVal;
rowKeyCache = currentDisplayData[this.pageObj.start + rowIndex][this.keyField];
}
if (this.isOnFilter) {
this.data.forEach(function(row) {
if (row[this.keyField] === rowKeyCache) {
row[fieldName] = newVal;
}
}, this);
if (this.filterObj !== null) this.filter(this.filterObj);
if (this.searchText !== null) this.search(this.searchText);
offset = currentDisplayData;
}
return this;
}

edit(newVal, rowIndex, fieldName, sectionKey) {
const currentDisplayData = this.getCurrentDisplayData();
let rowKeyCache;
if (!this.enablePagination) {
currentDisplayData[sectionKey][rowIndex][fieldName] = newVal;
rowKeyCache = currentDisplayData[sectionKey][rowIndex][this.keyField];
offset[rowIndex][fieldName] = newVal;
rowKeyCache = offset[rowIndex][this.keyField];
} else {
currentDisplayData[sectionKey][this.pageObj.start + rowIndex][fieldName] = newVal;
rowKeyCache = currentDisplayData[sectionKey][this.pageObj.start + rowIndex][this.keyField];
offset[this.pageObj.start + rowIndex][fieldName] = newVal;
rowKeyCache = offset[this.pageObj.start + rowIndex][this.keyField];
}
if (this.isOnFilter) {
this.data[sectionKey].forEach(function(row) {
offset.forEach(function(row) {
if (row[this.keyField] === rowKeyCache) {
row[fieldName] = newVal;
}
Expand Down

0 comments on commit 53f5f5b

Please sign in to comment.