如何将jquery数据表数据导出到excel? [英] How to export the jquery datatable data to excel ?

查看:79
本文介绍了如何将jquery数据表数据导出到excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我想将我的数据表数据导出为ex​​cel或pdf。在任何时候我点击我的要求意味着它应该工作。



我瞪着它但是我找不到能够更好地解释事情的好文章



代码编辑:

Hi
I want to export my datatable data to excel or pdf . At any point when i click on my requirement means it should work so .

I goggled it but i was unable to find good articles which supposed to explain things in better prospective

CODE EDIT :

<script  type="text/javascript">

    $(document).ready(function () {

 
        $("#btnExport").click(function(e) {
            window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#myDataTable').html()));
            e.preventDefault();
        });​

        $.datepicker.regional[""].dateFormat = 'dd/mm/yy';
        $.datepicker.setDefaults($.datepicker.regional['']);

        var tab=  $('#myDataTable').dataTable({
           
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "Company/DataProvider",
            "bJQueryUI": true,
            "aoColumns": [
                         {
                             "sName": "ID" 
                         },
                         { "sName": "COMPANY_NAME" },
                         { "sName": "ADDRESS" },
                         { "sName": "TOWN" }
            ]

        });
       

        tab.makeEditable({
            "aoColumns": [
                null,
                null,
                null,
                {
                indicator: 'Saving...',
                tooltip: 'Click to select town',
                loadtext: 'loading...',
                type: 'select',
                onblur: 'submit',
                loadurl: 'AjaxDataProvider1'
            
            }]
        });

    });

        </script>

}

<table id="myDataTable" class="display">
                    <thead>

                         <tr>
                            <th>ID</th>
                            <th>Company name</th>
                            <th>Address</th>
                           <th>Town</th>
                        </tr>
    
                    </thead>
                        
                    <tbody> 
                   </tbody>

                </table>

    <input type="button" id="btnExport" value="Export to Excel" />





我使用过一个链接和尝试这样的我不知道为什么我在其他系统中尝试相同的方式它在excel中显示我的一些列但现在它只是抛出我的错误:

CHROME:仅显示表格标题,列未加载

IE 10:第47行的JavaScript严重错误,http:// localhost:63553 /公司/索引中的第12列

SCRIPT1014:无效字符



事情是我删除了我为导出所做的代码片段以便将数据加到表格中成功加载。



希望得到更好的建议



问候



Well i used one of the link and tried like this I dont why same way i tried in other system its showing me some columns in excel but now its simply throwing me error like:
CHROME : Showing just table headings thats it , columns not getting loaded
IE 10 : JavaScript critical error at line 47, column 12 in http://localhost:63553/Company/Index
SCRIPT1014: Invalid character

Thing is when i removed the piece of code i done for exporting to excel the data to table getting loaded successfully .

Hoping for better suggestions

Regards

推荐答案

document )。ready( function (){
(document).ready(function () {


#btnExport)。click( function (e){
window .open(' data:application / vnd.ms-excel,' + encodeURIComponent(
("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + encodeURIComponent(


' #myDataTable')HTML()));
e.preventDefault();
});
('#myDataTable').html())); e.preventDefault(); });​


这篇关于如何将jquery数据表数据导出到excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆