admin管理员组文章数量:1323529
I have got a problem with getting information from jQuery datatable. Here is the table:
I would like to get information stored in the table. I have tried to do this by this:
var languages=[];
var people=[];
$("select[name='languageID']").each(function(){
languages.push( $(this).val() );
});
$("input:hidden[name='personID']").each(function(){
people.push( $(this).val() );
});
but it is getting values from current chosen page. If I run this in the situation like on the screenshot, only values from page 2 would be pushed to the arrays. I have tried to check where values from page 1 are stored, but I could not find anything. I also looked for it on jQuery datatables homepage
Could anyone help?
Regards
EDIT:
so I should do something like this:
table.column( 0 ).cache( 'search' ).each( function ( d ) { /*action here*/ } );
?
But what should be in action?
When I debug table.column( 2 ).cache( 'search' );
I have got this:
[ choose language ", " choose language ", " choose language ", " choose language ", " choose language ", " choose language " ]
It is first option in "Chosen language" select. I think, that I need something, which would return html code from each cell in column, so that I can analyse it later.
I have got a problem with getting information from jQuery datatable. Here is the table:
I would like to get information stored in the table. I have tried to do this by this:
var languages=[];
var people=[];
$("select[name='languageID']").each(function(){
languages.push( $(this).val() );
});
$("input:hidden[name='personID']").each(function(){
people.push( $(this).val() );
});
but it is getting values from current chosen page. If I run this in the situation like on the screenshot, only values from page 2 would be pushed to the arrays. I have tried to check where values from page 1 are stored, but I could not find anything. I also looked for it on jQuery datatables homepage
Could anyone help?
Regards
EDIT:
so I should do something like this:
table.column( 0 ).cache( 'search' ).each( function ( d ) { /*action here*/ } );
?
But what should be in action?
When I debug table.column( 2 ).cache( 'search' );
I have got this:
[ choose language ", " choose language ", " choose language ", " choose language ", " choose language ", " choose language " ]
It is first option in "Chosen language" select. I think, that I need something, which would return html code from each cell in column, so that I can analyse it later.
Share Improve this question edited Aug 6, 2014 at 21:17 Hladeo asked Aug 6, 2014 at 19:37 HladeoHladeo 5771 gold badge7 silver badges16 bronze badges 1- What version? The api has changed recently. – isherwood Commented Aug 6, 2014 at 19:56
4 Answers
Reset to default 5This one turns out harder than expected. At first, I try using the datatable data()
API, but that returns the dropdown lists as HTML strings, which are not very useful. Then I e across this article on how datatable deals with form inputs. The trick is to recognize that your datatable object can retrieve nodes from within the document regardless of paging.
A live demo can be found on my jsfiddle.
EDIT: As per discussion with OP, the following codes can be utilized instead of relying on embedded column selectors:
table.$('select[name="languageID"]').each(function(index, value{
languages.push($(value).val());
});
In the legacy api, fnGetData
should return what you need.
$(document).ready(function() {
oTable = $('#example').dataTable();
oTable.$('#myButton').click( function () {
var data = oTable.fnGetData( this );
// ... do something with the array / object of data for the row
} );
});
In the new api (v1.10+), you'll probably want column().cache()
.
http://datatables/reference/api/column().cache()
In my case, I should modify my code to:
var languages=[];
var people=[];
table
.column(0)
.nodes()
.each(function(a){
people.push( $(a).find("input:hidden[name='personID']").val() );
});
table
.column(2)
.nodes()
.each(function(a){
languages.push( $(a).find("select[name='languageID']").val() );
});
As @ivan.sim says, it's not so easy to get the full table data, although I finally found a solution which you can use to get values (including hidden inputs etc) from the full table including pages that are not displayed:
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var data = this.node();
console.log($(data).find('input').prop('checked'));
console.log($(data).find('input[name=someField]').val());
});
本文标签: javascriptjQuery Datatablesretrieving information from other pagesStack Overflow
版权声明:本文标题:javascript - jQuery Datatables - retrieving information from other pages - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120841a2421687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论