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

  • SEARCH
  • Home
  • 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 8533621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:00:26+00:00 2026-06-11T10:00:26+00:00

Right now I have the following html table: <table id=datatable> <thead> <th>fruits</th> <th>vegs</th> </thead>

  • 0

Right now I have the following html table:

<table id="datatable">
    <thead>
        <th>fruits</th>
        <th>vegs</th>
    </thead>
    <tbody>
        <tr>
            <td>apple</td>
            <td>potato</td>
        </tr>
        <tr>
            <td>apple</td>
            <td>carrot</td>
        </tr>
    </tbody>
</table>

And I’d like to reference the columns by name like this:

<script type="text/javascript">
$(document).ready(function() {  
    /* Init the table */
    var oTable = $('#datatable').dataTable( );

    //get by sTitle
    console.log(oTable);
    var row = oTable.fnGetData(1)
    console.log(row['vegs']);//should return 'carrot'
} );
</script>

Is there anyway to have a javascript function fnGetData() to return an object rather than an array when the datasource is DOM?

  • 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-11T10:00:28+00:00Added an answer on June 11, 2026 at 10:00 am

    So, I’ve researched a bit and found the datatable plugin is not very smart at handling columns – they are always arrays needed to be accessed with an integer. The only thing that handles columns and their properties is the aoColumns object – thanks at @JustinWrobel for finding the fnSettings method to access that object after initialisation. If you haven’t had this, you were stuck with $table.find("thead th").

    However, now it is easy to get the table as an array of objects:

    var table = $mytable.dataTable(​…);
    var cols = table.fnSettings().aoColumns,
        rows = table.fnGetData();
    
    var result = $.map(rows, function(row) {
        var object = {};
        for (var i=row.length-1; i>=0; i--)
            // running backwards will overwrite a double property name with the first occurence
            object[cols[i].sTitle] = row[i]; // maybe use sName, if set
        return object;
    });
    
    result[1]["vegs"]; // "carrot"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I have the following Perl code my $tmpl1="download1_video.html" if $file->{file_name}=~/\.(avi|divx|mkv|flv|mp4|wmv)$/i; $tmpl1||="download1.html"; so
Right now I have the following code working: @UiHandler(usernameTextBox) void onUsernameTextBoxKeyPress(KeyPressEvent event) { keyPress(event);
I want to match dates that have the following format: 2010-08-27, 2010/08/27 Right now
I got html code like the following: <p style=margin:0 0 0.5em 0;><b>Blablub</b></p> <table> ...
Right now I have the following piece of code: RSpec::Matchers.define :include_an_html_tag do |tag| tag
Right now I have the following code set up: $(function() { $('.thumbnail').mouseenter(function() { $('.thumbnail').fadeOut(200,
right now I'm following an Matlab tutorial http://www.mathworks.com/help/techdoc/creating_guis/brpat2g.html . The Problem is my Matlab
Good day! I right now have a function the drags an element from a
Right now I have an upload field while uploads files to the server. The
Right now I have a script that will get the last five files in

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.