Tablesorter -> Extracting filtered data to csv file

跟風遠走 提交于 2019-12-04 21:49:21

Use a new version of jQuery, since $().on is available only in jQuery 1.7+ and you are using jQuery 1.4.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>

You can use it for security, many javascript libraries use $ as default. Inside this .ready(), $ refers to jQuery object.

jQuery(document).ready(function($) {
        $(function() {                
            $('table').tablesorter({
                theme : 'blue',
                widgets: ['zebra', 'filter' ]
            });
        });

        $('.exportcsv').on('click', function(){
            var csv = [];
            // find only visible rows; we're ignoring filtered/hidden rows
            $('table').find('tbody tr:visible').find('td').each(function(){
                alert("Value of text" + $(this).text());                                    
                csv.push( $(this).text());                    
            });
            // do what you want with the csv data here
            $('textarea').val( csv.join(',') )
        });
});

jQuery v1.4 does not have an on() function, change it to use bind() instead.

$('.exportcsv').bind('click', function(){

Or update the version of jQuery you are using to version 1.7+

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!