Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:27:22+00:00 2026-06-02T08:27:22+00:00

I’m trying to link the items from a specific column, but each one will

  • 0

I’m trying to link the items from a specific column, but each one will be linked for a different id from the json string. Unfortunately I can’t find a way to do this using the API (I know there is a lot of ways to do that without using the API ), but I’m looking for a way to link a item from a column (each one with a link for a specific id).

So here is my code, I use getJSON to get the JSON from the server, and I load the data from this JSON to the table like this:

$.getJSON("http://url.from/method?parameter=foo&callback=?", function(data)
    {
        var total = 0;
        $("#table_body").empty();
        var oTable = $('#mytable').dataTable(
            {
                "sPaginationType" : "full_numbers",
                "aaSorting": [[ 0, "asc" ]]
            }); 

        oTable.fnClearTable();

        $.each(data, function(i, item) 
        {
            oTable.fnAddData(
                [
                    item.contact_name,
                    item.contact_email
                ]
            );
        });
    });

What I want to do, is for each row, link the contact_name to its id, which is also in the JSON, and can be accessed inside this $.each loop by using item.contact_id.

Is there a way to do this using DataTables API, if yes, could you explain me and provide a good resource that will help me with this?

OBS: I’m using JSONP

Thanks.


UPDATE WITH MY NEW CODE:

The error now is, I’m getting the id when I click, but due to the fact that I’m processing the rows inside the $.each loop, for any row I click, it will always get the id of the last processed row.

var options = 
        {
            "sPaginationType" : "full_numbers",
            "aaSorting": [[ 0, "asc" ]],
            "aoColumns": [{
                "sTitle": 'Name',
                "sClass": "dtName",
            }, {
                "sTitle": 'Email',
                "sClass": "dtEmail",
            }, {
                "bVisible": false
            }],
        }

        var oTable = $('#table').dataTable(options); // Creates a new instance of the DataTable

        oTable.fnClearTable();

        $.each(data, function(i, item) 
        {

            oTable.fnAddData(
                [
                    item.contact_name , 
                    item.contact_email,
                    item.contact_id
                ]
            );

            var rowData = oTable.fnGetData(i); // fetch all the ids into this array
            $('#table tbody tr').click( function() 
            {
                window.location.href = "/panel/contacts/"+rowData[2];
            });
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:27:25+00:00Added an answer on June 2, 2026 at 8:27 am

    Try it:

    var options = {
        "sPaginationType" : "full_numbers",
        "aaSorting": [[ 0, "asc" ]],
        "aoColumns": [{
            "sTitle": 'Name',
            "sClass": "dtName",
        }, {
            "sTitle": 'Email',
            "sClass": "dtEmail",
        }, {
            "bVisible": false
        }],
    }
    var oTable = $('#mytable').dataTable(options);
    

    This table will not display the id column, but you can get it like the following code:

    var rowData = oTable.fnGetData(rowNode);
    

    or

    var rowData = oTable.fnGetData(0); // for the first one
    
    console.log(rowData[0]);
    

    You can’t get it by jQuery because it’s not displayed.

    Edited: Sorry, I forgot one thing, when you use AddData put the item.contact_id on the third position:

    oTable.fnAddData([
        item.contact_name,
        item.contact_email,
        item.contact_id
    ]);
    

    If you want to get the id on click event do it:

    jQuery('#mytable tbody tr').live('click', function() {
        var selectedRow = oTable.fnGetData(this),
            url = "/yourUrl/" + selectedRow[2];
    
        window.location.replace(url);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.