我的工作代码基于 Tai Kitron 的回答。
添加了下面的 Grid col
'header'=>Html::checkbox('selection_all', false, ['class'=>'select-on-check-all', 'value'=>1,
'onclick'=>'
$(".kv-row-checkbox").prop("checked", $(this).is(":checked"));
if($(".kv-row-checkbox").prop("checked") === true) $(".delete_ready").attr("class","delete_ready warning");
if($(".kv-row-checkbox").prop("checked") === false) $(".delete_ready").attr("class","delete_ready");
']),
'contentOptions'=>['class'=>'kv-row-select'],
'content'=>function($model, $key){
if(isset($model->stopDelete)&&($model->stopDelete!==1))
return Html::checkbox('id[]', false, ['class'=>'kv-row-checkbox ',
'value'=>$key, 'onclick'=>'$(this).closest("tr").toggleClass("warning");', 'disabled'=> isset($model->stopDelete)&&($model->stopDelete===1)]);
else
return '';
//return Html::checkbox('selection[]', false, ['class'=>'kv-row-checkbox', 'value'=>$key, 'onclick'=>'$(this).closest("tr").toggleClass("danger");', 'disabled'=> isset($model->stopDelete)&&!($model->stopDelete===1)]);
},
'hAlign'=>'center',
'vAlign'=>'middle',
'hiddenFromExport'=>true,
'mergeHeader'=>true,
'width'=>'50px'
],
添加了以下行选项
'row_options'=>function($model){
if(empty($model->stopDelete)){
return ['class' => 'delete_ready'];
}
使用以下 javascript //删除选定的行 $(document).on('click', '#deleteSelected', function(){
var table = $('#deleteSelected').attr('value');
var keys = new Array();//[];//$('.deletSelectedItem:checked').val();
var path = 'global/deleteselected';
var current_page = location.pathname.substring(1);//window.location;
var c = 0;
$("input[name='id[]']:checked").each( function () {
keys[c] = $(this).val();
c++;
});
if( current_page.indexOf("index") >= 0){
path = '../global/deleteselected';
}
if(keys.length ==0){
krajeeDialog.alert("No Recorlds Selected")
}
else {
if(keys.length ==1)
var s = '';
else
var s ='s';
krajeeDialog.confirm("Are you sure you want to delete the selected "+keys.length+" recorld"+s+"?", function (result) {
if (result) {
$.post({
url: path,
data: {keylist: keys, table:table},
success: function (data) {
if( current_page.indexOf("index") >= 0)
$.pjax.reload({container: "#"+table});
else
$.pjax.reload({container: "#"+table, url: table});
}, error: function (xhr, status, error) {
alert(status + error);// check status && error
},
});
}
});
}
});
工作得很好。感谢您的帮助 Tai Kitron