How do I make the ID column of datatable into a link with a javascript function call
How do I make the ID column of datatable into a link with a javascript function call
I need to make the ID column as a "EDIT" link which will call a javascript function (in turn will pass the id to the next page for the data to be edited) like:
onclick=editUser(RegisteredUserID)
JAVASCRIPT
$('#user').dataTable({
"ajax": "users.txt",
/*columns: [
{'data': 'RegisteredUserID'},
{'data': 'UserName'},
{'data': 'EmailID'},
{'data': 'RegistrationCode'},
]*/
} );
HTML
<thead>
<tr>
<th>
ID
</th>
<th> User Name </th>
<th> Email </th>
<th> Registration Code </th>
</tr>
</thead>
<tbody>
</tbody>
JSON
{
"data": [{
"RegisteredUserID": "1",
"UserName": "User 1",
"EmailID": "user1@gmail.com",
"RegistrationCode": "REG1"
}, {
"RegisteredUserID": "2",
"UserName": "User 2",
"EmailID": "user2@gmail.com",
"RegistrationCode": "REG2"
}]
}
Answers
When
commented as shown in earlier throws the following error:
"Requested unknown parameter '0' for row 0 column 0" error is thrown columns not defined.
We'd need a link to a page showing the issue to be able to help debug the "Requested unknown parameter" issue.
Regarding the link, I would suggest you use a jQuery click event listener, or perhaps use a renderer to create an
a
tag if you want an actual link.Allan
Thanks for your response. Page with "Requested unknown parameter" issue is available at: http://myceindia.com/DataTable/DataTable.html
Regarding the link, I do not want an actual link. Could you please provide more detail on creating a clickable ID column (displaying text as"Edit" instead of ID) using jQuery click event listener to achieve the following:
I need something like this in the clickable link
so that the following function gets invoked:
Please suggest some approach on the above. Thanks