DataTables中设置checkbox回显选中
生活随笔
收集整理的這篇文章主要介紹了
DataTables中设置checkbox回显选中
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
在進(jìn)行編輯時(shí)DataTables中第一列的checkbox回顯默認(rèn)選中。
效果
實(shí)現(xiàn)
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_ 項(xiàng)結(jié)果","zeroRecords": "沒有匹配結(jié)果","info": "顯示第 _START_ 至 _END_ 項(xiàng)結(jié)果,共 _TOTAL_ 項(xiàng)","infoEmpty": "顯示第 0 至 0 項(xiàng)結(jié)果,共 0 項(xiàng)","infoFiltered": "(由 _MAX_ 項(xiàng)結(jié)果過濾)","infoPostFix": "","search": "搜索:","searchPlaceholder": "搜索...","url": "","emptyTable": "表中數(shù)據(jù)為空","loadingRecords": "載入中...","infoThousands": ",","paginate": {"first": "首頁(yè)","previous": "上頁(yè)","next": "下頁(yè)","last": "末頁(yè)"},"aria": {paginate: {first: '首頁(yè)',previous: '上頁(yè)',next: '下頁(yè)',last: '末頁(yè)'},"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),? //傳入組裝的參數(shù)contentType: "application/json",dataType: "json",success: function (result) {callback(result);}})}});} });?
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的DataTables中设置checkbox回显选中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot+MyBatisPl
- 下一篇: SpringBoot+Swagger2实