0

我是 jquery 和 Jqgrid 的新手。当未在 jqgrid 中选中复选框时,我在显示警报消息时遇到问题,即我已声明 multiselect:true。

function initJqGridSearchSubProject(table,pager,msg,loadSelID,caption,chkMrk ){

 $(table).empty();
 $(table).GridUnload();
 var mygrid =jQuery(table).jqGrid({
    datatype: "local",      
    data:msg,   
    width: 1240,
    scrollOffset:0,     
    height: 250,
    colNames:['ID','PID','Project Folder Name','Sub Project Name','Responsible','Status','Last Updated On'],
    colModel:[
    {name:'id',index:'id',hidden:true, width:5, sorttype:"int", editable: false,resizable:false},
    {name:'pid',hidden:true, width:5, sorttype:"int", editable: false,resizable:false},
    {name:'projectFolderName', width:250, editable: true,formatter:'tsLinks'},
    {name:'subProjectName', width:250, editable: true,formatter:'subProjectLinks'},
    {name:'responsible', width:200, editable:false,resizable:false},
    {name:'status', width:100,editable: true,stype:'select',edittype:"select",resizable:false,editoptions:{value:"ACTIVE:ACTIVE;INACTIVE:INACTIVE;DELETED:DELETED",readonly:false},editrules:{edithidden:false}},   
    {name:'lastUpdatedOn', width:200,editable: false,resizable:false,sorttype:'date',formatter:'date',formatoptions:{ srcformat: 'M d y H:i:s', newformat: 'd M y h:i A' }}

        ],
    pager: pager,
    rowNum:200,     
    rowList:[200,400,600,1000],
    //rowTotal:2000,                    
    //loadOnce:true,    
    //rownumbers:true,
    gridview : true,
    //sortname: 'lastUpdatedOn',                    
    viewrecords: true,
    //sortorder: "desc",                    
    toppager:true,
    multiselect:true,
    singleselect: false, 
    //multiboxonly:true,
    //toolbar: [true,'both'],                   
    caption:caption,
    hidegrid: false,
    gridComplete:function(id){
    //$(chkMrk).hide();
    //alert('grid complete');
    },

     beforeSelectRow: function(rowid, e)
    {
        // reset check box selection only when user clicks on another checkbox
        if($(e.target).is("input:checkbox"))
        {
            // reset/clear other checkboxes selection before making a latest clicked row's checkbox as selected
            jQuery(table).jqGrid('resetSelection');
        }

        // Code To Disable Check Box Selection When User Selects by Clicking on A Row
        return $(e.target).is("input:checkbox");
        //return(true);
    }

});

jQuery(table).jqGrid('navGrid',pager,{del:false,add:false,edit:false,search:false,refresh:true,cloneToTop:true,afterRefresh:function(){}},{},{},{},{}); 
jQuery(table).jqGrid('navButtonAdd', table+ '_toppager_left',{caption:"Add WO", buttonicon:"ui-icon ui-icon-plus",id:"SUBPROJID", onClickButton: function(){},position:"first",title:"Add WO"});
}); 

这是我的整个代码jqgrid ...我有一排带有prjt名称和子项目名称的字段,我使用多选来在所有字段的行之前显示复选框,它要求用户单击一个复选框以显示其他页面,如果用户不检查,则应向他显示一条警报消息以检查任何复选框。

4

2 回答 2

0

在最后一行使用它来取消选中最后选择的复选框

jQuery(this).attr('checked', false);

完整代码

jQuery(document).ready(function(){
jQuery('input:checkbox').change(
function(){

if (jQuery('input:checkbox:checked').length == jQuery('input:checkbox').length){

    alert('Alert Text.');
jQuery(this).attr('checked', false);
}
});
});
于 2013-04-03T09:57:46.377 回答
0

我希望我理解您的要求。您将自定义按钮“添加 WO”添加到导航栏,如果单击按钮时未选择任何行,则需要显示警报消息,或者如果选择了某些行,则需要重定向到另一个页面。

$(this).jqGrid("getGridParam", "selarrrow")您可以使用或使用$(this).jqGrid("getGridParam", "selrow")inside of获取所选行的列表,onClickButton如果用户单击按钮,则会调用该列表。内部参数selrow表示最后选择的行的rowid。如果$(this).jqGrid("getGridParam", "selrow")为空,则不选择任何行。该调用$(this).jqGrid("getGridParam", "selarrrow")获取另一个内部参数“selarrrow”的值,该参数是选定 ID 的数组。如果使用时会填写multiselect:true

所以我认为如果selrownull或者如果selarrrow是空数组,你可以向用户显示警告。如果需要重定向到另一个 HTML 页面,您可以为location.href.

于 2013-04-03T10:37:45.903 回答