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

JayakumaJayakuma Posts: 4Questions: 1Answers: 0

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

  • JayakumaJayakuma Posts: 4Questions: 1Answers: 0

    When

    columns: [
            {'data': 'RegisteredUserID'}, 
            {'data': 'UserName'},
            {'data': 'EmailID'},
            {'data': 'RegistrationCode'},
        ]
    

    commented as shown in earlier throws the following error:

    "Requested unknown parameter '0' for row 0 column 0" error is thrown columns not defined.

  • allanallan Posts: 63,794Questions: 1Answers: 10,513 Site admin

    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

  • JayakumaJayakuma Posts: 4Questions: 1Answers: 0

    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

    onclick=editUser(RegisteredUserID) 
    

    so that the following function gets invoked:

    function submitform(RegisteredUserID)
            {
                document.getElementById('hdnID').value = RegisteredUserID;
                document.getElementById('frmRegisteredUsers').submit();
            }
    
  • JayakumaJayakuma Posts: 4Questions: 1Answers: 0

    Please suggest some approach on the above. Thanks

This discussion has been closed.