setValue code path crashing on cell[x]
I'm upgrading from v2 to v3 to test v3 and have run into an issue when attempting to set a cell value of type text. Am getting a JS error on the lines below, referencing cell[i] as undefined:
if (keys.length > 0) {
for (var i = 0; i < keys.length; i++) {
var x = cell[i].getAttribute('data-x');
var y = cell[i].getAttribute('data-y');
// Update cell
records.push(obj.updateCell(x, y, value));
I've debugged into the code and cell is an element already and, for example, NOT a jQuery object, so cell.getAttribute would work but cell[i] is undefined.
Can you send me the full code, on jsfiddle?
Hi Paul, I'm heading out of town on vacation so won't be able to do that until I get back on Monday.
For what it's worth, I'm doing my own custom validation on the worksheet where if a cell is required to have a value, I'm adding a class to it that highlights the border and applies a tooltip via title attribute. I'm doing this using jQuery selectors so this may be throwing off the code that gets the keys collection and thinks cell is a jQuery object?
For example, if I wanted to "save" my worksheet, the process would first validate the required fields. I clear out any existing "error" cells, i.e., where $container is just my selector of '#worksheetId'
$container.find('.jexcel_content table.jexcel tbody td:not(.jexcel_row).jexcel_cell_error')
.removeClass('jexcel_cell_error').attr('title', '');
Then I apply the failed validation class to any cell that needs it, e.g.,
$(worksheetTable.records[validationResult.rowIndex][validationResult.columnIndex])
.addClass('jexcel_cell_error').attr('title', validationResult.message);
I hope this helps until I can get a jsFiddle in place for you.
Thank, I would be very happy to fix that for you when I have the code.
Regards
Here's the jsFiddle you asked for. I put a comment on the line that breaks it. Let me know if you need anything else.
Essentially, the added key by jQuery is what causes the code to think it should treat the element as a jQuery element. Probably should add more checks to the lines below from the setValue function.
var keys = Object.keys(cell);
if (keys.length > 0) {
I've applied this fix currently to get me moving so I'm not blocked:
//if (keys.length > 0) {
if (cell instanceof jQuery) {
If you would like to still using jquery you can refer to the Documentation v2 even using v3... You example:
var table = $('#worksheet').jexcel({
columns: [{
"title": "Origin",
"width": 155,
"align": "left",
"type": "text"
},
{
"title": "Destination",
"width": 191,
"align": "left",
"type": "text"
},
{
"title": "Directionality",
"width": 161,
"align": "left",
"type": "text"
},
{
"title": "Discount Percent",
"width": 146,
"align": "left",
"type": "text"
} ],
columnDrag: false,
columnSorting: false,
columnResize: true,
rowDrag: false,
allowInsertColumn: false,
allowManualInsertColumn: false,
allowDeleteColumn: false,
allowRenameColumn: false,
allowComments: false,
search: false,
onselection: worksheet_OnChange
});
Any other method, for exaample:
$('#worksheet').jexcel('insertRow')
Your example fixed.
https://jsfiddle.net/paulhodel/rvj6a0xk/
Okay thanks. I can change my code to do that. How would you recommend I then would get the cell for say the onselection event handler from the input parameters?
...
worksheet_OnSelect = function(worksheetInstance, borderLeft, borderTop, borderRight, borderBottom)
{...}
Normally, I'd do something like this:
$destinationCell = $container.find('td[data-x={0}][data-y={1}]'.format(borderLeft, borderTop))
Let me know if you have a better recommendation. Thanks much.
I am not sure if I get your question. The onselection will send you same arguments:
if (typeof(obj.options.onselection) == 'function') {
obj.options.onselection(el, borderLeft, borderTop, borderRight, borderBottom, origin);
}
My question is how do I get the cell element? The el that is passed in is the worksheet and not the cell and origin is always undefined which is why I resorted to using borderLeft and borderTop with jQuery selector to get the cell element.
In vanilla:
if (typeof(obj.options.onselection) == 'function') { obj.options.onselection(el, x1, y1, x2, y2, origin); }
var firstCell = table.records[y1][x1] var lastcell = table.records[y2][x2]
I don't want to update your code but do what I can outside of it. Since I'm using jQuery, how do I get the table object? I was using the non-jquery implementation at first but then I ran into this bug. The solution to this bug was to go back to using jQuery which is fine but I need to be able to get the table object to do what you suggest above. Is there a way to get the options from the jQuery jexcel, .e.g, $ws.jexcel('options') or something like that? Thanks.
Also, this bug is still an issue with the master branch. I grabbed the master this morning and now I'm back to getting the same error re cell[x].

config = $('#spreadsheet').jexcel('getConfig')
Thank you. btw, really appreciate how quick you respond. :)
Looks like the records collection is missing from the config via $('#spreadsheet').jexcel('getConfig').
Sorry,
I got confused. What you need is not the Options, but the main jexcel object.
var table = document.getElementById('yourspreadsheet').jexcel;
table.setValue() table.insertRow()
etc...
On Tue, Jun 25, 2019 at 2:52 PM A. Yousif [email protected] wrote:
Looks like the records collection is missing from the config via $('#spreadsheet').jexcel('getConfig').
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/paulhodel/jexcel/issues/377?email_source=notifications&email_token=ABN5VAKH47ENUY3FQERWENDP4IPLHA5CNFSM4HZDQ6L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYQKCSA#issuecomment-505454920, or mute the thread https://github.com/notifications/unsubscribe-auth/ABN5VAOX6R7PX2OLHGJRTU3P4IPLHANCNFSM4HZDQ6LQ .
Cells... table.records[y][x]
On Tue, Jun 25, 2019 at 3:02 PM Paul Hodel [email protected] wrote:
Sorry,
I got confused. What you need is not the Options, but the main jexcel object.
var table = document.getElementById('yourspreadsheet').jexcel;
table.setValue() table.insertRow()
etc...
On Tue, Jun 25, 2019 at 2:52 PM A. Yousif [email protected] wrote:
Looks like the records collection is missing from the config via $('#spreadsheet').jexcel('getConfig').
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/paulhodel/jexcel/issues/377?email_source=notifications&email_token=ABN5VAKH47ENUY3FQERWENDP4IPLHA5CNFSM4HZDQ6L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYQKCSA#issuecomment-505454920, or mute the thread https://github.com/notifications/unsubscribe-auth/ABN5VAOX6R7PX2OLHGJRTU3P4IPLHANCNFSM4HZDQ6LQ .
Cool, thanks again.
...> Also, this bug is still an issue with the master branch. I grabbed the master this morning and now I'm back to getting the same error re cell[x].
Any thoughts on this issue?
Here's a new jdFiddle that duplicates the issue even though I changed it to use jQuery style. This is a showstopper right now because I can't add any values. In the interim, I can apply the "fix" that checked for instanceof jQuery.
Hi Paul, due to time constraints, we're going to back out of v3 for now until it's a bit more stable. We'll go back to v2 which is stable in our framework and we need it to be in jQuery UI's dialog since part of our app uses dialogs off of main views. So when we do go to v3, we will need it to function under the dialog.
I'll try to get a jsFiddle if I can in the next week or so where v3 would come up fine the first time we bring it up in a dialog, but once we close the dialog and reopen it, jexcel doesn't render anything. I'll create a new bug entry for that and hopefully can reproduce in jsFiddle.
I'm also having the same issue regarding
Object doesn't support property or method 'getAttribute'
Which occurs here...
var getCellCoords = function(element) {
var x = element.getAttribute('data-x');
var y = element.getAttribute('data-y');
if (x && y) {
return [x, y];
} else {
if (element.parentNode) {
return getCellCoords(element.parentNode);
}
}
};
This is a new implementation, nothing in production yet. I don't want to move forward with it like this. Anything I can correct?