0

I'm trying to call a function from within a jquery plugin.

The example code is:

$("#table-2").tableDnD({
    onDragClass: "myDragClass",

    onDrop: function(table, row) {
        var rows = table.tBodies[0].rows;
        var debugStr = "Row dropped was "+row.id+". New order: ";
        for (var i=0; i<rows.length; i++) {
            debugStr += rows[i].id+" ";
        }
        $(#debugArea).html(debugStr);
    },

    onDragStart: function(table, row) {
        $(#debugArea).html("Started dragging row "+row.id);
    }
});

The definition of onDrop taken from http://isocra.com/2008/02/table-drag-and-drop-jquery-plugin/ is

onDrop

Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table and the row that was dropped. You can work out the new order of the rows by using table.tBodies[0].rows.

Is it possible to pass a function to this ? eg :

onDrop: doWork(table, row),

Where doWork is:

function doWork (table, row) {
  var row_id = $(row).prop('id');
}

The error is get is: Uncaught ReferenceError: table is not defined(…) which relates to the line I added for doDrop.

Anyone know anyway to do this ? Thanks.

2 Answers 2

1

When you write

onDrop: doWork(table, row),

You are calling the function doWork with those parameters. As table doesn't exists it throws the error.

The correct way to do what you are trying is

onDrop: doWork,

This way you are setting the function you want to call.

Sign up to request clarification or add additional context in comments.

Comments

0

try:

    onDrop: function(table, row) {
        doWork(table, row)
    }

1 Comment

Although this code may help to solve the problem, it doesn't explain why and/or how it answers the question. Providing this additional context would significantly improve its long-term educational value. Please edit your answer to add explanation, including what limitations and assumptions apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.