简体   繁体   English

datatables jQuery插件获取单列数据并添加到textarea

[英]datatables jQuery plug-in get single column data and add to textarea

I have a table of data using jQuerys datatables plug-in (awesome plug-in!!) and I need to have the data from the email column dynamicly added to a text area everytime the table is filtered or updated. 我有一个使用jQuerys datatables插件(很棒的插件!)的数据表,每次过滤或更新该表时,我都需要将email列中的数据动态地添加到文本区域。

Can this be done? 能做到吗? If yes then how? 如果是,那怎么办?

I have looked through all the documentation on the website and cant find this. 我浏览了网站上的所有文档,找不到此文件。

You can probably start with the events live demo code. 您可能可以从事件现场演示代码开始。 Their example shows timestamps getting appended to a textarea whenever the datatable is sorted, filtered, or paged. 他们的示例显示了在对数据表进行排序,过滤或分页时,时间戳会附加到textarea That sounds a lot like what you'd like to do: 这听起来很像您要执行的操作:

http://datatables.net/release-datatables/examples/advanced_init/dt_events.html http://datatables.net/release-datatables/examples/advanced_init/dt_events.html

function eventFired( type ) {
    var n = document.getElementById('demo_info');
    n.innerHTML += '<:div>:'+type+' event - '+new Date().getTime()+'<:/div>:';
    n.scrollTop = n.scrollHeight;      
}

$(document).ready(function() {
    $('#example')
        .bind('sort',   function () { eventFired( 'Sort' ); })
        .bind('filter', function () { eventFired( 'Filter' ); })
        .bind('page',   function () { eventFired( 'Page' ); })
        .dataTable();
} );

That should take care of your requirement to handle filtering. 那应该照顾您处理过滤的要求。 I'm not sure I understand the "updated" requirement, but if you are looking for a way to run the code when the datatable is live, this example may help: 我不确定我是否了解“更新的”要求,但是如果您正在寻找一种在数据表处于活动状态时运行代码的方法,则此示例可能会有所帮助:

http://datatables.net/release-datatables/examples/advanced_init/events_live.html http://datatables.net/release-datatables/examples/advanced_init/events_live.html

$('#example tbody tr').live('click', function () { ... });

I got this answer from Allan @ datatables: 我从Allan @ datatables得到了这个答案:

Use fnDrawCallback to run a function that will fire whenever the table is updated. 使用fnDrawCallback运行可在表更新时触发的函数。 Then perhaps use fnGetData or the plug-in fnGetColumnData API methods to get the data and stick it into a text field using standard DOM / jQuery methods. 然后,也许使用fnGetData或插件fnGetColumnData API方法来获取数据,并使用标准DOM / jQuery方法将其粘贴到文本字段中。

Allan 艾伦

I followed this method to get the results I wanted. 我遵循这种方法来获得所需的结果。

Hope this helps others. 希望这对其他人有帮助。

C C

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM