Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unselect the selected row from jQgrid when the custom formatter text field value is empty

When i tried to check the check box in jQgrid it selecting the values that's fine ,and in that i have the custom formatter text field with out entering the values in text field and tried to select the check box i will display the alert message after that i will uncheck the checkbox but the focus is not get removed from the grid.

I have attached the screen shot please let me know the answer.

code is pasted here:

    jQuery("#list1").jqGrid({               

        url:actionurl,
        mtype: 'POST',          
        colNames:['PartnerId', 'Employee No','Employee Name' ,'Position', 'Position Id', 'Wages','Relieve Date','Days Required'],
        colModel:[                    
                      {name:'partnerId',index:'partnerId', width:280,sortable:true,search:false, hidden: true},
                      {name:'em_ka003_employeeno',index:'em_ka003_employeeno', width:200,sortable:true},
                      {name:'empname',index:'empname', width:280,sortable:false,search:false},
                      {name:'position',index:'position', width:250,sortable:false,search:false},
                      {name:'positionId',index:'positionId', width:0,sortable:false,search:false,hidden:true},                    
                      {name:'wages',index:'wages', width:100,sortable:false,search:false},                        
                      {name:'emp_relievedate',index:'emp_relievedate', width:200,sortable:false,search:false},
                      {name:'daysrequired',index:'daysrequired', width:140,sortable:false,search:false,formatter:createText},
                ],

        rowNum:10,
        rowList:[5,10,15],
        pager: '#pager1',         
        sortorder: "asc",
        sortname: 'em_ka003_employeeno', 
        viewrecords: true,
        rownumbers: true,
        loadonce: false,
        forceFit: true,
        datatype: 'xml',
        multiselect: true , 
        footerrow:true,
        userDataOnFooter:true,
        onSelectRow: function(rowId)
            { 
                handleSelectedRow(rowId); 
            },
        caption: "<b>Labor Extension",
        gridComplete: function() {          

            $.unblockUI();
        }



});

This is my custom formatter function:

function createText(el, cellval, opts)
    {
         return "<span><input class='dojoValidateValid required TextBox_OneCell_width number' type='text' id='days_req"+cellval.rowId+"' name='days_req"+cellval.rowId+"'  onKeyPress='return checkIt(event,false)'/></span>";

    }

function handleSelectedRow(id) 
{

var jqgcell     = jQuery('#list1').getCell(id, 'partnerId');
var daysrequired = jQuery("#days_req"+id+"").val();
var cbIsChecked = (jQuery("#jqg_list1_"+jqgcell).attr('checked'));

if(cbIsChecked==true)
 {

    /* Append the Days Required */


if(daysrequired=="")
    {

        alert("please enter the extension days");
        jQuery("#days_req"+id+"").focus();
        jQuery("#jqg_list1_"+jqgcell).attr('checked', false);
          jQuery('#list1').restoreRow(id);

        return false;
    }



 }

In first screen shot if the user if selecting the check box without entering the value in textbox it shows alert.In second screen shot the focus is not get removed.

like image 977
simbu94 Avatar asked Jul 14 '11 13:07

simbu94


1 Answers

I got the answer.

If the text field value is zero while selecting the particular row in jqgrid at that time validate that with javascript and uncheck the selected row from the grid.

Here is the working code i pasted below:

if(daysrequired=="0")
    {
        myGrid.jqGrid('resetSelection');
    }
  • myGrid is my grid id.
  • resetSelection is a method in the jQGrid to unselect the selected rows.
like image 95
simbu94 Avatar answered Oct 09 '22 07:10

simbu94