How to pass the 'row' parameter from a render function to an external function?

How to pass the 'row' parameter from a render function to an external function?

Ragos1027Ragos1027 Posts: 4Questions: 2Answers: 0
edited July 2021 in DataTables 1.10

Hi, I can't figure out how to do this simple thing after a long time searching.

I have a render function within a column.
In that function I create an input element, and within that element I define an onclick function.
In that onclick function I want to pass the row parameter (so that I can read/modify that particular row).

Render function:

render: function (data, type, row, meta) {                                    
            return '<input id="userState" type="checkbox" class="toggle" onclick="userState('+ row +')" checked>';
}

And then the onclick function:

function estadoUsuario(userRow) {
    userRow['state'].data("Inactive");                         // I want to modify a column here from that row
    anotherFunction( userRow['id'].data() );                   // I want to pass the data inside a column here
}

In that onclick function I want to:

1) Modify the data in the 'state' column,
2) Pass the data in the 'id' column to another function

I'm getting syntax errors/unexpected identifiers errors because for sure I'm not writing it properly

Thanks a lot in advance

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,292Questions: 26Answers: 4,768

    Take a look at this thread with a similar question. If it doesn't help then please provide the test case Colin asked for.

    Kevin

Sign In or Register to comment.