Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new to JQuery. I am trying to create a DataTable. All the functionality works very well. But in DataTable records first column is userid, say 1,2,3 etc which are hyperlink to user profile page. i.e. when click on 1, it will call /userprofile.jsp?id=1 ..I don't know how to make these changes.Any help appreciated.
Posted
Updated 3-Dec-13 23:38pm
v3

I never worked with jsp. But here an idea.
Based on your description, you're binding 1 on first column. Instead create a hyperlink there with URL.

Before
HTML
<td>1</td>

After
HTML
<td><a href="/userprofile.jsp?id=<b>1</b>">1</a></td>

Create dynamic URL with ID value & put that hyperlink in first column.
 
Share this answer
 
The fnRender function helps to create the links using the values of the other columns. You can use the oObj.aData to get the values of the other column like id to generate the links.

JavaScript
$(document).ready(function () {
        $('#companies').dataTable({
            bProcessing: true,         
            sAjaxSource: '@Url.Action("Index1", "Default1")',
            aoColumns: [
                      null, // first column (RoleId)
                      null, // second column (RoleName)  
                      null, // third (UserId)
                      null, // fourth (UserName)

                      {     // fifth column (Edit link)
                        "sName": "RoleId",
                        "bSearchable": false,
                        "bSortable": false,
                        "fnRender": function (oObj)                              
                        {
                            // oObj.aData[0] returns the RoleId
                            return "<a href="/Edit?id=" <br mode="hold" />                                + oObj.aData[0] + "">oObj.aData[0]</a>";
                        }
                       },


                   ]
     });
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900