DataTables中设置checkbox回显选中
生活随笔
收集整理的這篇文章主要介紹了
DataTables中设置checkbox回显选中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
在進行編輯時DataTables中第一列的checkbox回顯默認選中。
效果
實現
dataTables賦值代碼
?columns: [{ data: 'id' ,"orderable" : false},{ data: 'goodsLocationNumber' },{ data: 'locationTypeName' ,"orderable" : false},{ data: 'saveMaterialTypeName' ,"orderable" : false},{ data: 'materielStatusName',"orderable" : false},{ data: 'shelveName' ,"orderable" : false},{ data: 'remark',"orderable" : false }],columnDefs: [{//?? 指定第1列,從0開始,0表示第一列,1表示第二列……"targets": 0,"bSortable": false,"render": function(data, type, row, meta) {if (row.isSelected == 1){return '<input type="checkbox" class="checkchild" onclick="childClick(this)" checked="checked" value="' + row.id + '" />'}return '<input type="checkbox" class="checkchild" onclick="childClick(this)" value="' + row.id + '" />'}}],完整初始化DataTables代碼
$(document).ready(function() {//獲取下拉框的值,判斷是否為空,不為空則是編輯,那么就要初始化dataTablesvar selected = $("#businessInitiator option:selected").val();if(selected!=""){var t = $('#example').DataTable({"language": {"processing": "處理中...","lengthMenu": "顯示 _MENU_ 項結果","zeroRecords": "沒有匹配結果","info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項","infoEmpty": "顯示第 0 至 0 項結果,共 0 項","infoFiltered": "(由 _MAX_ 項結果過濾)","infoPostFix": "","search": "搜索:","searchPlaceholder": "搜索...","url": "","emptyTable": "表中數據為空","loadingRecords": "載入中...","infoThousands": ",","paginate": {"first": "首頁","previous": "上頁","next": "下頁","last": "末頁"},"aria": {paginate: {first: '首頁',previous: '上頁',next: '下頁',last: '末頁'},"sortAscending": ": 以升序排列此列","sortDescending": ": 以降序排列此列"},"decimal": "-","thousands": "."},"processing": true,"searching" : false,"pageLength": 100,"serverSide": true,"columnDefs": [ {"searchable": false,"orderable": false,"targets": "_all",}],"dom": '<"top">rt<"bottom"flpi><"clear">',columns: [{ data: 'id' ,"orderable" : false},{ data: 'goodsLocationNumber' },{ data: 'locationTypeName' ,"orderable" : false},{ data: 'saveMaterialTypeName' ,"orderable" : false},{ data: 'materielStatusName',"orderable" : false},{ data: 'shelveName' ,"orderable" : false},{ data: 'remark',"orderable" : false }],columnDefs: [{//?? 指定第1列,從0開始,0表示第一列,1表示第二列……"targets": 0,"bSortable": false,"render": function(data, type, row, meta) {if (row.isSelected == 1){return '<input type="checkbox" class="checkchild" onclick="childClick(this)" checked="checked" value="' + row.id + '" />'}return '<input type="checkbox" class="checkchild" onclick="childClick(this)" value="' + row.id + '" />'}}],"ajax": function (data, callback, setting) {data.editActionId = $("#refundOrderId").val();data.selected=selected;$.ajax({type: 'POST',url: "/busGoodsLocation/getRejectsLocationsList",cache: false,? //禁用緩存//async: true,data: JSON.stringify(data),? //傳入組裝的參數contentType: "application/json",dataType: "json",success: function (result) {callback(result);}})}});} });?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的DataTables中设置checkbox回显选中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot+MyBatisPl
- 下一篇: SpringBoot+Swagger2实