jQuery 当自定义格式化程序文本字段值为空时如何从 jQgrid 中取消选择选定的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6693914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to unselect the selected row from jQgrid when the custom formatter text field value is empty
提问by simbu94
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.
当我尝试检查 jQgrid 中的复选框时,它选择了很好的值,并且我有自定义格式化文本字段而没有在文本字段中输入值并尝试选择复选框我将在此之后显示警报消息我将取消选中该复选框,但焦点不会从网格中移除。
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;
}
}
回答by simbu94
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.
如果当时在 jqgrid 中选择特定行时文本字段值为零,请使用 javascript 验证并取消选中网格中的选定行。
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.
myGrid
是我的网格 ID。resetSelection
是 jQGrid 中取消选择所选行的一种方法。