Skip to content

Commit

Permalink
prepare extend to setDATA, fix insertColumn undo/redo
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhodel authored and paulhodel committed Nov 7, 2019
1 parent db4caba commit ab8aecd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
65 changes: 35 additions & 30 deletions dist/jexcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@ var jexcel = (function(el, options) {
}

obj.createTable = function() {
// Data
obj.prepareData();

// Elements
obj.table = document.createElement('table');
obj.thead = document.createElement('thead');
Expand Down Expand Up @@ -603,28 +600,6 @@ var jexcel = (function(el, options) {
}
}

/**
* Make sure the data is in the correct format (json/array)
*
* @param data
* @return void
*/
obj.prepareData = function() {
var data = [];

if (obj.options.data) {
for (var j = 0; j < obj.options.data.length; j++) {
var row = [];
for (var i = 0; i < obj.options.columns.length; i++) {
row[i] = obj.options.data[j][obj.options.columns[i].name];
}
data.push(row);
}

obj.options.data = data;
}
}

/**
* Set data
*
Expand All @@ -646,6 +621,20 @@ var jexcel = (function(el, options) {
obj.options.data = [];
}

// Prepare data
if (obj.options.data) {
var data = [];
for (var j = 0; j < obj.options.data.length; j++) {
var row = [];
for (var i = 0; i < obj.options.columns.length; i++) {
row[i] = obj.options.data[j][obj.options.columns[i].name];
}
data.push(row);
}

obj.options.data = data;
}

// Adjust minimal dimensions
var j = 0;
var i = 0;
Expand Down Expand Up @@ -834,7 +823,9 @@ var jexcel = (function(el, options) {
// Update cell
var columnName = jexcel.getColumnNameFromId([ i, rowNumber ]);
// Set value
obj.setValue(columnName, data[i]);
if (data[i] != null) {
obj.setValue(columnName, data[i]);
}
}
}

Expand All @@ -850,6 +841,20 @@ var jexcel = (function(el, options) {
return dataset;
}

/**
* Set a column data by colNumber
*/
obj.setColumnData = function(colNumber, data) {
for (var j = 0; j < obj.rows.length; j++) {
// Update cell
var columnName = jexcel.getColumnNameFromId([ colNumber, j ]);
// Set value
if (data[j] != null) {
obj.setValue(columnName, data[j]);
}
}
}

/**
* Create row
*/
Expand Down Expand Up @@ -2619,7 +2624,7 @@ var jexcel = (function(el, options) {
if (height > 0) {
// In case the column is an object
if (typeof(row) == 'object') {
column = $(row).getAttribute('data-y');
row = $(row).getAttribute('data-y');
}

// Oldwidth
Expand Down Expand Up @@ -3724,7 +3729,7 @@ var jexcel = (function(el, options) {
columnNumber:columnNumber,
numOfColumns:numOfColumns,
insertBefore:insertBefore,
columns:properties.columns,
columns:properties,
headers:historyHeaders,
colgroup:historyColgroup,
records:historyRecords,
Expand Down Expand Up @@ -7171,9 +7176,9 @@ if (typeof(jQuery) != 'undefined') {
$.fn.jexcel = function(method) {
var spreadsheetContainer = $(this).get(0);
if (! spreadsheetContainer.jexcel) {
jexcel($(this).get(0), arguments[0]);
return jexcel($(this).get(0), arguments[0]);
} else {
spreadsheetContainer.jexcel[method].apply(this, Array.prototype.slice.call( arguments, 1 ));
return spreadsheetContainer.jexcel[method].apply(this, Array.prototype.slice.call( arguments, 1 ));
}
};

Expand Down
Loading

0 comments on commit ab8aecd

Please sign in to comment.