jquery.dataTable.js 繪製表格使用詳解__js

來源:互聯網
上載者:User

dataTable.js繪製表格真的是很不錯,下面看看如何應用吧。

先匯入dataTable.js的庫吧。

定義html頁面。

<div>   <div id="result">        <div class="close_btn"></div>        <table class="table table-hover table-striped" id="resulttable" >            <thead>            <tr>                <th>編號</th>                <th>單位代碼</th>                <th>名稱</th>                <th>總個數</th>                <th>面積</th>            </tr>            </thead>                 </table>    </div></div>
js代碼

 
var resulttable = $('#resulttable').DataTable({    destroy: true,    // data: tableData,    order: [[ 2, "desc" ]],    fnDrawCallback: function(){        this.api().column(0).nodes().each(function(cell, i) {            cell.innerHTML =  i + 1;        });    },    pageLength:10,    language: {        "sProcessing": "處理中...",        "sLengthMenu": "顯示 _MENU_ 項結果",        "sZeroRecords": "沒有匹配結果",        "sInfo": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",        "sInfoEmpty": "顯示第 0 至 0 項結果,共 0 項",        "sInfoFiltered": "(由 _MAX_ 項結果過濾)",        "sInfoPostFix": "",        "sSearch": "搜尋:",        "sUrl": "",        "sEmptyTable": "表中資料為空白",        "sLoadingRecords": "載入中...",        "sInfoThousands": ",",        "oPaginate": {            "sFirst": "首頁",            "sPrevious": "上頁",            "sNext": "下頁",            "sLast": "末頁"        },        "oAria": {            "sSortAscending": ": 以升序排列此列",            "sSortDescending": ": 以降序排列此列"        }    }});

這樣你可以直接用ajax請求得到資料:

$.ajax({    url: url,    type: type,    data: {f:"json"},    timeout: 3600000,    dataType: 'json',    success: function (res) {        var features= res;        for(var j in features){            //計算面積            var a  = features[j].attributes.qsdwdm;            var b  = features[j].attributes.dlmc;            var c  = features[j].attributes.COUNT;            var d  = features[j].attributes.SUM_tbmj;            resulttable.row.add(['',a,b,c,d.toFixed(2)]).draw().node();        }    },    error: function (res) {        callback(res);    }});

這裡注意
d.toFixed(2)
就是面積保留2位小數點。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.