Datatable get the values of all rows of a specific column
up vote
0
down vote
favorite
How to get all values of all rows of a specific column?
Basically what I want to achieve is, get all the values from 'Key'
column and push to allAdminKeys
array as global variable because I need those values in somewhere else.
var t = $('#adminKeysTable').DataTable( {
"ajax": {
"url": getKeysById,
"dataSrc": function(json) {
var rows = ;
for (var i=0;i<json.keys.length;i++) {
//skip rows "if a condition is met"
//here just any rows except row #1
if (json.keys[i].privileges == '32')
rows.push(json.keys[i]);
}
return rows;
}
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "key" },
{ "data": null }
],
"columnDefs": [
{ "targets": 0, "searchable": false, "orderable": false},
{ "targets": 2, "name": "key"},
{ "targets": -1, "defaultContent": '<div class="tb-btn regenerate-btn" id="btnRegenerateAdminKey" data-toggle="modal" data-target="#regenerateAdminKeyConfirmation"></div>'}
],
"order": [[ 1, 'asc' ]],
"paging": false,
"ordering": false,
"info": false,
'processing': true
} );
var allAdminKeys = ;
var rowData = t.rows().data(); //t is my table
$.each($(rowData), function(key,value){
allAdminKeys.push(value["key"]); //filter by "Key" column
})
console.log(allAdminKeys); // returning an empty array
javascript jquery datatable
add a comment |
up vote
0
down vote
favorite
How to get all values of all rows of a specific column?
Basically what I want to achieve is, get all the values from 'Key'
column and push to allAdminKeys
array as global variable because I need those values in somewhere else.
var t = $('#adminKeysTable').DataTable( {
"ajax": {
"url": getKeysById,
"dataSrc": function(json) {
var rows = ;
for (var i=0;i<json.keys.length;i++) {
//skip rows "if a condition is met"
//here just any rows except row #1
if (json.keys[i].privileges == '32')
rows.push(json.keys[i]);
}
return rows;
}
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "key" },
{ "data": null }
],
"columnDefs": [
{ "targets": 0, "searchable": false, "orderable": false},
{ "targets": 2, "name": "key"},
{ "targets": -1, "defaultContent": '<div class="tb-btn regenerate-btn" id="btnRegenerateAdminKey" data-toggle="modal" data-target="#regenerateAdminKeyConfirmation"></div>'}
],
"order": [[ 1, 'asc' ]],
"paging": false,
"ordering": false,
"info": false,
'processing': true
} );
var allAdminKeys = ;
var rowData = t.rows().data(); //t is my table
$.each($(rowData), function(key,value){
allAdminKeys.push(value["key"]); //filter by "Key" column
})
console.log(allAdminKeys); // returning an empty array
javascript jquery datatable
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values fromKey
column.
– jenna_3108
Nov 9 at 7:32
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
1
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How to get all values of all rows of a specific column?
Basically what I want to achieve is, get all the values from 'Key'
column and push to allAdminKeys
array as global variable because I need those values in somewhere else.
var t = $('#adminKeysTable').DataTable( {
"ajax": {
"url": getKeysById,
"dataSrc": function(json) {
var rows = ;
for (var i=0;i<json.keys.length;i++) {
//skip rows "if a condition is met"
//here just any rows except row #1
if (json.keys[i].privileges == '32')
rows.push(json.keys[i]);
}
return rows;
}
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "key" },
{ "data": null }
],
"columnDefs": [
{ "targets": 0, "searchable": false, "orderable": false},
{ "targets": 2, "name": "key"},
{ "targets": -1, "defaultContent": '<div class="tb-btn regenerate-btn" id="btnRegenerateAdminKey" data-toggle="modal" data-target="#regenerateAdminKeyConfirmation"></div>'}
],
"order": [[ 1, 'asc' ]],
"paging": false,
"ordering": false,
"info": false,
'processing': true
} );
var allAdminKeys = ;
var rowData = t.rows().data(); //t is my table
$.each($(rowData), function(key,value){
allAdminKeys.push(value["key"]); //filter by "Key" column
})
console.log(allAdminKeys); // returning an empty array
javascript jquery datatable
How to get all values of all rows of a specific column?
Basically what I want to achieve is, get all the values from 'Key'
column and push to allAdminKeys
array as global variable because I need those values in somewhere else.
var t = $('#adminKeysTable').DataTable( {
"ajax": {
"url": getKeysById,
"dataSrc": function(json) {
var rows = ;
for (var i=0;i<json.keys.length;i++) {
//skip rows "if a condition is met"
//here just any rows except row #1
if (json.keys[i].privileges == '32')
rows.push(json.keys[i]);
}
return rows;
}
},
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "key" },
{ "data": null }
],
"columnDefs": [
{ "targets": 0, "searchable": false, "orderable": false},
{ "targets": 2, "name": "key"},
{ "targets": -1, "defaultContent": '<div class="tb-btn regenerate-btn" id="btnRegenerateAdminKey" data-toggle="modal" data-target="#regenerateAdminKeyConfirmation"></div>'}
],
"order": [[ 1, 'asc' ]],
"paging": false,
"ordering": false,
"info": false,
'processing': true
} );
var allAdminKeys = ;
var rowData = t.rows().data(); //t is my table
$.each($(rowData), function(key,value){
allAdminKeys.push(value["key"]); //filter by "Key" column
})
console.log(allAdminKeys); // returning an empty array
javascript jquery datatable
javascript jquery datatable
edited Nov 9 at 7:42
asked Nov 9 at 7:28
jenna_3108
8919
8919
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values fromKey
column.
– jenna_3108
Nov 9 at 7:32
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
1
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43
add a comment |
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values fromKey
column.
– jenna_3108
Nov 9 at 7:32
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
1
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values from
Key
column.– jenna_3108
Nov 9 at 7:32
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values from
Key
column.– jenna_3108
Nov 9 at 7:32
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
1
1
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
"initComplete": function(settings, json){
for (var i=0;i<json.keys.length;i++) {
allAdminKeys.push(json.keys[i].key);
}
}
Managed to achieve what I wanted by adding this.
add a comment |
up vote
0
down vote
You can use .columns()
function to access the data
let col = 0 // can be column index or css class of column header
// get all cells of the column
const cells = $yourDataTable.columns(col).nodes()
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
"initComplete": function(settings, json){
for (var i=0;i<json.keys.length;i++) {
allAdminKeys.push(json.keys[i].key);
}
}
Managed to achieve what I wanted by adding this.
add a comment |
up vote
0
down vote
"initComplete": function(settings, json){
for (var i=0;i<json.keys.length;i++) {
allAdminKeys.push(json.keys[i].key);
}
}
Managed to achieve what I wanted by adding this.
add a comment |
up vote
0
down vote
up vote
0
down vote
"initComplete": function(settings, json){
for (var i=0;i<json.keys.length;i++) {
allAdminKeys.push(json.keys[i].key);
}
}
Managed to achieve what I wanted by adding this.
"initComplete": function(settings, json){
for (var i=0;i<json.keys.length;i++) {
allAdminKeys.push(json.keys[i].key);
}
}
Managed to achieve what I wanted by adding this.
answered Nov 9 at 8:48
jenna_3108
8919
8919
add a comment |
add a comment |
up vote
0
down vote
You can use .columns()
function to access the data
let col = 0 // can be column index or css class of column header
// get all cells of the column
const cells = $yourDataTable.columns(col).nodes()
add a comment |
up vote
0
down vote
You can use .columns()
function to access the data
let col = 0 // can be column index or css class of column header
// get all cells of the column
const cells = $yourDataTable.columns(col).nodes()
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use .columns()
function to access the data
let col = 0 // can be column index or css class of column header
// get all cells of the column
const cells = $yourDataTable.columns(col).nodes()
You can use .columns()
function to access the data
let col = 0 // can be column index or css class of column header
// get all cells of the column
const cells = $yourDataTable.columns(col).nodes()
answered Nov 9 at 8:59
Phap Duong Dieu
692
692
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221439%2fdatatable-get-the-values-of-all-rows-of-a-specific-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What are you getting when you run the code? Are there any errors?
– Lloyd Francis
Nov 9 at 7:29
@LloydFrancis no errors but getting an empty array. It seems like not retrieving the values from
Key
column.– jenna_3108
Nov 9 at 7:32
Why do you have the $ in front of the (rowData) in your $.each?
– SakoBu
Nov 9 at 7:34
1
Seems the rowData is a variable... I'm a little confused why you would do that... Please provide more code... is there an index.html?
– SakoBu
Nov 9 at 7:34
@SakoBu I'm actually referring to this
– jenna_3108
Nov 9 at 7:43