Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
below is my html code :
HTML
<div class="widget-content nopadding">
            <table id="LoanInfoAsGuarantor" class="table table-bordered data-table">
                <thead>
                    <tr>
                        <th>Account No</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>


javascript code :

var dsLoans = [
["12344"],
["12345"],
];

$(document).ready(function () {


$('#Loan').DataTable(
{
"bDestroy": true,
bJQueryUI: true,
"aaData": dsLoans,
"sPaginationType": "full_numbers"
});
});

need output should be with anchor text of account number.

What I have tried:

i have tried to find several questions but did not get big help.
Posted
Updated 20-Dec-16 3:52am

1 solution

Use the columns.render option[^], as demonstrated in this example[^].
JavaScript
$('#Loan').DataTable({
    "destroy": true,
    "jQueryUI": true,
    "data": dsLoans,
    "pagingType": "full_numbers",
    "columnDefs": [
        {
            "targets": 0,
            "render": function ( data, type, row ) {
                if (type === "display") {
                    return "<a href=\"someUrl?account=" + encodeURIComponent(data) + "\">" + data + "</a>";
                }
                
                return data;
            }
        }
    ]
});
 
Share this answer
 
Comments
jayeshkumar.rathod 21-Dec-16 12:22pm    
Thanks for your reply,

i tried to use your code by help of your given link but as i have a sting array as a data source how can i set for specific column Ex- Account No?

i have tried to select the column based on "row" but failed.. !!

What is "if (type === "display")" ?
Richard Deeming 21-Dec-16 12:34pm    
With a string array, you only have one column. Use the targets property of the column definition to specify which column you're targeting.
https://datatables.net/reference/option/columnDefs.targets[^]

If you read the render documentation[^], you'll see that the function will be called for different data types - display value, sort value, search value, etc. You only want to add the link to the display value.
Orthogonal data[^]

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