fnGetNodes after fnAddData causes nTr undefined error
fnGetNodes after fnAddData causes nTr undefined error
chris.e.simpson
Posts: 6Questions: 0Answers: 0
Hi,
After adding a new row into my grid using fnAddData, I have it so the user can reposition the new row in the grid by using move up and move down buttons.
However on the first click of move up I get an error: "Cannot read property 'nTr' of undefined"
This is occurring during to a call to fnGetNodes. It doesn't happen after an equivalent fnUpdate of an existing row.
Is there something I'm missing?
Thanks
Chris
After adding a new row into my grid using fnAddData, I have it so the user can reposition the new row in the grid by using move up and move down buttons.
However on the first click of move up I get an error: "Cannot read property 'nTr' of undefined"
This is occurring during to a call to fnGetNodes. It doesn't happen after an equivalent fnUpdate of an existing row.
Is there something I'm missing?
Thanks
Chris
This discussion has been closed.
Replies
Allan
This is not on the public internet sadly but I can post some code. I've tried to trim this down to the important bits.
The error is occurring on this line:
var targetRow = $(this.fnGetNodes(iRow));
Hope it makes sense.
[code]
Nucleus.Controls.Command.updateCommandList = function(com) {
/*if it's a new command*/
if (com.index == -1) {
...
Nucleus.Controls.Command.commandGrid.fnAddData([com.index, 0, com.name, Nucleus.Controls.Command.operationSummaryText(com.operations)]);
else {
...
}
Nucleus.Controls.Command.commandGrid.fnReOrder();
Nucleus.Controls.Command.commandGrid.fnBindToLinks();
Nucleus.Controls.Command.commandGrid.fnDraw();
}
Nucleus.Controls.Command.commandGrid.fnReOrder = function() {
/*set the order column*/
var tbl = this;
var i = 1;
$(this.fnSettings().aoData).each(function(index, element) {
if ($(element.nTr).find("td:visible").length) {
tbl.fnUpdate((i++).toString(), index, 1);
}
});
}
Nucleus.Controls.Command.commandGrid.fnMoveUp = function(iRow) {
/*make sure the given row has a visible row above it*/
var targetRow = $(this.fnGetNodes(iRow));
var prevRow = targetRow.prev("tr:visible");
if (prevRow.length) {
var targetOrder = targetRow.find("td:first").text();
var prevOrder = prevRow.find("td:first").text();
/*as soon as we update this it might move so fetch the position again*/
this.fnUpdate(targetOrder.toString(), this.fnGetPosition(prevRow[0]), 1);
this.fnUpdate(prevOrder.toString(), this.fnGetPosition(targetRow[0]), 1);
}
}
Nucleus.Controls.Command.commandGrid.fnBindToLinks = function() {
...
goes through and sets up the anchors in the grid
...
}
[/code]
Thanks
Chris
Interesting way of updating the positioning! Have you got sorting disabled? I ask because I guess once the sorting has been change, the order will be shifted. Can a sorting plug-in now achieve what you are looking for here?
Allan
[code]
$("#commandMoveUp").bind("click", function() {
var tr = $(".row_selected:first")[0];
if (tr) {
Nucleus.Controls.Command.commandGrid.fnMoveUp(Nucleus.Controls.Command.commandGrid.fnGetPosition(tr));
Nucleus.Controls.Command.commandGrid.fnDraw()
Nucleus.Runtime.setConfirmUnload(true);
}
});
[/code]
As you can see I use fnGetPosition to find the row so I would have thought this would work.
I'll add the line in you suggest though and see what I get.
Yes, I don't want user sorting on this grid, the order of items is very important. I'll take a look into a sorting plug in to see if that can make it more simple.
Thanks
This is so terribly unsatisfactory but I added your debug line in and the problem went away. I removed the debug code and the problem was still gone.
I think possible as a result of resolving some other bugs in that javascript file I may have inadvertently fixed this one but it's near impossible to track what change has done it.
I'm going to test in various browsers but I can't seem to break this one again. Fixing an issue without knowing why is a great recipe for future problems but I think I'll have to admit this has gone away now.
Thanks for your time though.
Cheers
Chris
Good to hear it's working now though.
Allan