DataTables手动带参数提交至服务器
一:参数传递及接收
JavaScript:
黄背景部分为参数传递关键
<script type="text/javascript"> var table; var delId; $(document) .ready(function () { table = $('#tableQuetions') .dataTable({ //"dom": '<"H"fr > t <"F"lip >', "pagingType": "full_numbers", "processing": true, "serverSide": true, "scrollX": true, "ordering ": false, "scrollY": "350px", "searching": false, "ajax": { "url": "/RFTraining/Exam/ExamQuetionList", "type": "POST", "data": function (d) { d.questionName = $("#QuestionNameForSearch").val(); d.questionType = $("#QuestionTypeForSearch").val(); } }, "columnDefs": [ { "render": function (data, type, row) { return '<input type="button" value="删除" class="btn btn-link" onclick="onDel(' + row["ID"] + ')" />'; //+'<input type="button" value="编辑" class="btn btn-link" onclick="onEdit(' + //row["ID"] + //')" />'; }, "targets": 6 } ], columns: [ { data: 'ROWNO' }, { data: 'ID' }, { data: 'QUESTIONTYPE' }, { data: 'QUESTIONNAME' }, { data: 'QUESTIONSCORE' }, { data: 'CREATETIME' }, { data: 'edit' } ], "lengthMenu": [ [20, 50, 100, 200], [20, 50, 100, 200] ], //每页显示条数设置 "Info": true, "oLanguage": { //国际语言转化 "oAria": { "sSortAscending": " - click/return to sort ascending", "sSortDescending": " - click/return to sort descending" }, "sLengthMenu": "显示 _MENU_ 记录", "sZeroRecords": "对不起,查询不到任何相关数据", "sEmptyTable": "未有相关数据", "sLoadingRecords": "玩命加载中...", "sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录。", "sInfoEmpty": "当前显示0到0条,共0条记录", "sInfoFiltered": "(数据库中共为 _MAX_ 条记录)", "sProcessing": "玩命加载中...", "sSearch": "模糊查询:", "sUrl": "", //多语言配置文件,可将oLanguage的设置放在一个txt文件中,例:Javascript/datatable/dtCH.txt "oPaginate": { "sFirst": "首页", "sPrevious": " 上一页 ", "sNext": " 下一页 ", "sLast": " 尾页 " } } }); }); } </script>
C#:
参数获取
rfExamQuetion.QuestionName = Request.Params["questionName"]; rfExamQuetion.QuestionType = int.Parse(Request.Params["questionName"]);
二:自定义提交
table.ajax.reload();//官方写的是这个,不知道为啥我用的时候报错TypeError: cannot read property 'reload' of undefined 'ajax' table.api().ajax.reload();//上面报错的可以用这个方法
相关推荐
xiaoge00 2020-03-01
83443560 2014-06-28
ywy0 2018-05-05
bluemengcom 2017-12-07
郭贝贝编程 2017-05-24
yongyonglsy 2016-11-07
momode 2016-10-06
lpch0 2016-09-01
jiaojiao0 2016-07-14
83443560 2015-04-28
asdjkl 2015-03-20
SanBa 2014-11-07
LingPF 2019-06-27
lqadam 2014-03-17
Chydar 2019-06-26
XiaoSpring 2013-03-11
黑色幽默 2012-10-17
83453065 2012-06-04