DEVPROCB DEVPROCB - 1 year ago 53
Javascript Question

How to use a Table as a Data Source Using Jquery

I thought I would share this with other users as it does not appear to be something that is covered but may help some people working with tables and data. Also Any suggestions on some better code would be greatly appreciated. I tried to make this as simple and streamaligned as possible. I wrote this code after hours of trying to find a super simple solution to use td's in a table as a datasource. DataTables just did not cut it as there was just too much bulk. I needed something super efficient that allowed me to use data from essentially any table and any column I choose and I knew the specific td/column I wanted it from. This should essentially allow you to use any table with a specific column to pull data right out and populate it to an array. Which you can then use globally.

I hope this helps anyone looking to use table as a true data source.

Answer Source
var thisismyarray = []

$( "table tr td:nth-child(2)" ).each(function( index ) {
var thecolumnIwant = $(this).text();


console.log("this is the array stuff:"+thisismyarray.toString())   ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download