Skip to content

Commit

Permalink
#124. Fix edit after search on > 1 page rows
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Sep 24, 2018
1 parent 063194a commit 0f6d3a4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gigatables-react",
"version": "2.7.9",
"version": "2.7.10",
"description": "GigaTables is a ReactJS plug-in to help web-developers process table-data in applications and CMS, CRM, ERP or similar systems. It supports ajax data processing/editing (CRUD), pagination, cross-sorting, global search, shft/ctrl rows selection, 7 popular languages and more.",
"main": "./build/index.js",
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/Reactables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class Reactables extends Main {
getEditor(display) {
const {editor} = this.props;
if (typeof editor !== CommonConstants.UNDEFINED) {

const {
active,
action,
Expand All @@ -396,6 +397,7 @@ class Reactables extends Main {
popup_title,
fieldsEdit
} = this.state;

const {
tableOpts,
lang,
Expand Down
51 changes: 31 additions & 20 deletions src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {Component} from 'react';
import Row from './table/Row.js';
import Column from './table/Column.js';
import Footer from './table/Footer';
import Editor from './form/Editor';

const CommonConstants = require('./CommonConstants');
const EditorConstants = require('./EditorConstants');
Expand Down Expand Up @@ -152,6 +151,7 @@ class Main extends Component {
if (dataSearch !== null) {
jsonData = dataSearch;
}

let jsonDataPerPage = jsonData;
if (jsonData.length > perPage) {
let from = parseInt(fromRow),
Expand All @@ -163,6 +163,7 @@ class Main extends Component {
jsonDataPerPage = jsonData.slice(from, to);
}
}

// process rows
jsonDataPerPage.forEach((object, objectIndex) => {
let cols = [], rowId = 0;
Expand All @@ -180,6 +181,7 @@ class Main extends Component {
key={-1}
editableCells={editableCells}></Column>);
}

// process cols
this.props.children.forEach((th, idx) => {
const {data} = th.props;
Expand Down Expand Up @@ -210,6 +212,7 @@ class Main extends Component {
>{content}</Column>);
}
});

// count is used to shft key + click selection of rows, ex.: sorted
rows.push(<Row
clickedRow={this.clickedRow.bind(this)}
Expand All @@ -221,16 +224,20 @@ class Main extends Component {
gteRowId={rowId}
editableCells={editableCells}>{cols}</Row>);
});

if (aggregateFooter === true) {
this.setFooter(jsonDataPerPage, rows);
}

let state = {
dataRows: rows,
countRows: jsonData.length
};

if (typeof sortedButtons !== CommonConstants.UNDEFINED) {
state['sortButtons'] = sortedButtons;
}

this.setState(state);
}

Expand Down Expand Up @@ -587,12 +594,14 @@ class Main extends Component {
}, () => {
this.createTable(this.jsonData, sortedButtons);
});

this.hidePopup();
}

handlePagination(e) {
const {from} = e.target.dataset;
const {perPage, sortedButtons} = this.state;

this.setState({
fromRow: parseInt(from),
page: parseInt(from / perPage + 1),
Expand Down Expand Up @@ -643,25 +652,8 @@ class Main extends Component {
popup_title = this.lang.gte_editor_popupheader_edit;
popup_button = this.lang.gte_editor_sendbtn_update;

// collect data for fields filling in Editor
if (dataSearch !== null) { // edit field(s) after search todo: test - seems like a bug if there are > 1 page results
for (let k in selectedRows) {
if (selectedRows.hasOwnProperty(k)) {
fieldsEdit[k] = dataSearch[selectedRows[k]];
}
}
} else {
for (let sKey in selectedIds) {
if (selectedIds.hasOwnProperty(sKey)) {
for (let jsonKey in this.jsonData) {
if (this.jsonData.hasOwnProperty(jsonKey)
&& this.jsonData[jsonKey][CommonConstants.GT_ROW_ID] === selectedIds[sKey]) {
fieldsEdit[sKey] = this.jsonData[jsonKey];
}
}
}
}
}
// collect data for fields filling in Editor, edit field(s) after search
fieldsEdit = this.setPopUpFields(dataSearch !== null ? dataSearch : this.jsonData);
break;
case EditorConstants.ACTION_DELETE:
popup_title = this.lang.gte_editor_popupheader_delete;
Expand All @@ -685,6 +677,25 @@ class Main extends Component {
}
}

setPopUpFields(data) {
let fields = {};

const {selectedIds} = this.state;

for (let sKey in selectedIds) {
if (selectedIds.hasOwnProperty(sKey)) {
for (let jsonKey in data) {
if (data.hasOwnProperty(jsonKey)
&& data[jsonKey][CommonConstants.GT_ROW_ID] === selectedIds[sKey]) {
fields[sKey] = data[jsonKey];
}
}
}
}

return fields;
}

hidePopup() {
this.setState({
active: false
Expand Down
4 changes: 4 additions & 0 deletions src/components/form/CSVLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ class CSVLink extends Component {
if (typeof jsonData === CommonConstants.UNDEFINED || !jsonData.length) {
return;
}

let date = new Date();
let dateFormat = date.getFullYear() + '_' + (date.getMonth() + 1) + '_' + date.getDate() + '_' + date.getHours() + '_' + date.getMinutes() + '_' + date.getSeconds();
let csvContent = '';

// headers
csvContent += this.objectToCSVRow(Object.keys(jsonData[0]));
jsonData.forEach((item) => {
csvContent += this.objectToCSVRow(item);
});

let blob = new Blob([csvContent], {type: CommonConstants.CSV_HEADER});

if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
Expand Down

0 comments on commit 0f6d3a4

Please sign in to comment.