datatable.js使用
Posted running-fly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了datatable.js使用相关的知识,希望对你有一定的参考价值。
$(document).ready(function () { var southtable = $("#southtable").DataTable({ language: { url: ‘/lib/jquery.datatables/js/‘ + LANG + ‘.json‘ }, ordering: false, searching: false, processing: true, paging: false, columns:[ {data:‘prose‘}, {data:‘fightGroup‘}, {data:‘p1Name‘}, {data:‘p1Rid‘}, {data:‘p2Name‘}, {data:‘p2Rid‘}, {data:‘winner1‘}, {data:‘winner2‘}, {data:‘winner3‘}, ] }); var northtable = $("#northtable").DataTable({ language: { url: ‘/lib/jquery.datatables/js/‘ + LANG + ‘.json‘ }, ordering: false, searching: false, processing: true, paging: false, columns:[ {data:‘prose‘}, {data:‘fightGroup‘}, {data:‘p1Name‘}, {data:‘p1Rid‘}, {data:‘p2Name‘}, {data:‘p2Rid‘}, {data:‘winner1‘}, {data:‘winner2‘}, {data:‘winner3‘}, ] }); function ajaxLoad(){ southtable.clear().draw(); northtable.clear().draw(); $(".dataTables_processing").css("display", "block"); window._PlatId = $("#PlatId").val(); $.ajax({ data: { _csrf: $("meta[name=‘csrf-token‘]").attr("content"), PlatId: $("#PlatId").val(), partition: $("#Partition").val(), time: $("#time").val(), }, type:‘get‘, dataType:‘json‘ }).done(function(data) { $(".dataTables_processing").css("display", "none"); if(data.flag == 0 || data.info.data.length == 0){ return false; } data.info.data.south.length == 0 || southtable.rows.add(data.info.data.south).draw(); data.info.data.north.length == 0 || northtable.rows.add(data.info.data.north).draw(); }); } $(".search-form").submit(function () { ajaxLoad(); return false; }); southtable.on("init", function(){ if($("#PlatId").val()!=‘‘&&$("#Partition").val()!=‘‘&&$("#time").val()!=‘‘){ ajaxLoad(); } }); });
<div class="row"> <div class="col-md-12"> <div class="block-flat"> <div class="header"> <h4><?= Yii::t(Yii::$app->controller->module->id, ‘查询结果‘) ?></h4> </div> <div class="southtable"> <div> <table id="my_table" class="table table-bordered"> <thead> <tr> <th style="width: 10%;"><?= Yii::t(Yii::$app->controller->module->id, ‘对局‘) ?></th> <th style="width: 10%;"><?= Yii::t(Yii::$app->controller->module->id, ‘角色a‘) ?></th> <th style="width: 10%;"><?= Yii::t(Yii::$app->controller->module->id, ‘rid‘) ?></th> <th style="width: 10%;"><?= Yii::t(Yii::$app->controller->module->id, ‘角色b‘) ?></th> <th style="width: 10%;"><?= Yii::t(Yii::$app->controller->module->id, ‘rid‘) ?></th> <th style="width: 15%;"><?= Yii::t(Yii::$app->controller->module->id, ‘首次击杀‘) ?></th> <th style="width: 15%;"><?= Yii::t(Yii::$app->controller->module->id, ‘剩余人数是否≤3‘) ?></th> </tr> </thead> </table> </div> </div> </div> </div> </div>
以上是关于datatable.js使用的主要内容,如果未能解决你的问题,请参考以下文章
使用 DataTable.js 在 asp.net gridview 中使用下拉列表按列过滤