0

I am new to jquery and Jqgrid. I have problems displaying an alert message, when the checkbox is not selected in jqgrid, i.e i have declared the 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"});
}); 

This is my whole code jqgrid... I have a rows of fields with prjt names and subprjects names, where i use multiselect, to display the checkbox before the row for all fields, Its mandate that user should click one checkbox to show other page,where if user does not check, he should be shown an alert message to check any checkbox.

  • Your question is unclear. Initially grid are created with all checkbox in not selected state. I don't think that you want show alert message immediately. What you really need? In what situation you want to display warning (the alert message)? – Oleg Apr 03 '13 at 09:40
  • @Oleg I have declared multiselect:true and beforeSelectRow function, so we can click on only one field and add to the database, so when user not checked the checkbox of any field, we should show an alert to check a checkbox.!! – Sendhil Kumar Apr 03 '13 at 09:44
  • The code which you posted don't contain any `beforeSelectRow` callback. Moreover you use `datatype: "local"` so one can't speak about some remote database. One use typically `datatype: "json"` or `datatype: "xml"` with remote data source. In any way you should *modify the text/code of your question* to describe more clear what you do, what problem you have and what you need. – Oleg Apr 03 '13 at 09:52
  • @Oleg...this is my whole code...where there is a add button, when the user clicks the add button, its should check the fields is checked or not, if it is checked, it should go to the other page. if not it should show the alert message to check the checkbox of any field. – Sendhil Kumar Apr 03 '13 at 10:23

2 Answers2

0

Use this in last line to uncheck last selected check box

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

Full code

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);
}
});
});
John
  • 539
  • 1
  • 4
  • 15
0

I hope that I undertand correct your requirements. You added custom button "Add WO" to the navigator bar and you need display alert message if no row is selected when the button are clicked or to redirect to another page if some row is do selected.

You can get the list of selected rows using $(this).jqGrid("getGridParam", "selarrrow") or using $(this).jqGrid("getGridParam", "selrow") inside of onClickButton, which will be called if the user click on the button. The internal parameter selrow represent the rowid of last selected row. If $(this).jqGrid("getGridParam", "selrow") is null then no row is selected. The call $(this).jqGrid("getGridParam", "selarrrow") get the value of another internal parameter "selarrrow" which is array of selected ids. If will be filled in case of usage multiselect:true.

So I think that you can display warning to the user if selrow is null or if selarrrow is empty array. If the need to redirect to another HTML page you can assign new value to location.href.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I have written a function for Add button to show a popup.! But am facing the other issue now..? – Sendhil Kumar Apr 04 '13 at 04:10
  • http://stackoverflow.com/questions/15802685/the-reset-button-is-not-working-properly-jqgrid – Sendhil Kumar Apr 04 '13 at 04:45
  • But now a facing the new problem for reset the filter it refreshes the whole page and having some problem in filtering. http://stackoverflow.com/questions/15802685/the-reset-button-is-refreshing-the-filter-bar-as-well-in-jqgrid – Sendhil Kumar Apr 04 '13 at 09:37
  • @SendhilKumar: We have all a lot of problems. You should divide there in small questions which could have some value for *other people*. The goal of stackoverflow is not providing helper forum where somebody from the world solve all your problems for free. The goal is sharing small *common* problems and the solutions of the problems. So you should not just ask all your problems in different questions or in one question. You should close small solved problems to go forward. – Oleg Apr 04 '13 at 09:43
  • @SendhilKumar: You described your problem in [the comment](http://stackoverflow.com/questions/15783763/alert-message-when-checkbox-is-not-selected#comment22441270_15783763). I provided the answer on the problem. Is it what you wanted or you have some questions *about the problem or about my suggestion*. You should close one problem and not jump to other problems which you have more. – Oleg Apr 04 '13 at 09:48
  • @ Oleg Am sorry,I have solved the current problem and i accept it. – Sendhil Kumar Apr 04 '13 at 09:51
  • @ Oleg am new to this Stackflow and jqgrid..hope..i wont make any mistakes again..am having issue to be solved..about the reset process.!? Am need of help now..! – Sendhil Kumar Apr 04 '13 at 09:57
  • @SendhilKumar: I need do my main job now. I'll take a look in your question later. Probably somebody else help you till before. To have no misunderstanding in usage of stackoverflow you should read FAQs [here](http://stackoverflow.com/faq) or [here](http://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites). – Oleg Apr 04 '13 at 10:01