防止单击添加按钮时打开表单
你们知道当我单击添加按钮时如何防止打开表单吗?
也许使用 beforeShowForm ?
function(formid)
{
if(jQuery('#gridap').getGridParam('selrow'))
{
idgridap=jQuery('#gridap').getGridParam('selrow');
jQuery('#FK_numerocontrato_ap',formid).val(idgridap).attr('readonly','readonly');
}
else
{
// I want to prevent the openning of the add form here and maybe show an alert using the "alertcap"
}
}
CHECAROW;
$grid->setNavEvent('add','beforeShowForm',$checarowid);
BTW,有没有办法调用jqgrid的alertmod并向其添加自定义消息?
谢了!
Did you guys know how to prevent the open of a Form when I click on a add button?
Maybe using beforeShowForm?
function(formid)
{
if(jQuery('#gridap').getGridParam('selrow'))
{
idgridap=jQuery('#gridap').getGridParam('selrow');
jQuery('#FK_numerocontrato_ap',formid).val(idgridap).attr('readonly','readonly');
}
else
{
// I want to prevent the openning of the add form here and maybe show an alert using the "alertcap"
}
}
CHECAROW;
$grid->setNavEvent('add','beforeShowForm',$checarowid);
BTW, there's a way to call the alertmod of jqgrid and add a custom message to it?
tks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白为什么您不直接从导航栏中删除“添加”按钮。要创建导航栏,您需要显式调用 jqGrid 的
navGrid
方法,或者
但
navGrid
有其他参数(请参阅 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator)。因此,如果您使用,将不会有“添加”按钮。
如果您确实需要“添加”按钮,请更清楚地解释您的情况。顺便说一下 http://www.trirand 中描述的方式。 com/jqgridwiki/doku.php?id=wiki:custom_buttons 您可以添加一个自定义按钮,并从您这边完全控制。如果您放置了图标的名称,您可以在页面 http://jqueryui.com/themeroller/ 上找到将光标悬停在页面底部“框架图标”区域的图标上。自定义按钮可以具有与“添加”按钮相同的图标。它能解决您的问题吗?
更新:在您发表评论后,我现在明白您的问题了。我可以建议使用
navGrid
的addfunc
选项(请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator&s[]=navgrid)。因此,代码可能如下所示:在此示例中,仅当选择一行时才允许单击“添加”按钮。您将看到一个消息框,其中包含类似“请选择行”的文本(该文本在grid.locale-en.js中定义
$.jgrid.nav.alerttext
> 或您使用的其他本地化文件)。您可以将此代码片段放置在主网格中。拒绝“添加”操作的代码可以更简单,我只是在这里复制了使用 jqGrid 本身的代码片段。您可以改为显示自定义错误消息。
I don't understand why you not just remove "Add" button from the navigation bar. To create a navigation bar you explicitly call
navGrid
method of jqGridor
but
navGrid
has additional parameters (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator). So if you useyou will be have no "Add" button.
If you do need have "Add" button, please explain your situation more clear. By the way with the way described in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons you can add an custom button with full control from your side. The name of icon you can find on the page http://jqueryui.com/themeroller/ if you place a cursor over the icon on the "Framework Icons" area on the bottom of the page. The custom button can have the same icon as the "Add" button has. Can it solve your problem?
UPDATED: Now after your comment I understand your problem. I can suggest to use
addfunc
option ofnavGrid
(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator&s[]=navgrid). So the code could looks like following:In this example will be allowed to click "Add" button only if a row is selected. You will see a message box with the text like "Please, select row" (the text which defines
$.jgrid.nav.alerttext
inside of grid.locale-en.js or other localization file which you use). You can place this code fragment in your master grid.The code in case of denying of "Add" operation can be easier, I just copied here a code fragment which use jqGrid itself. You can display your custom error message instead.
酷,谢谢奥列格!
顺便说一句,我提出了另一个(但不是很漂亮)的解决方案:
** 这是一个 aftershowform 操作。
如果我们在主网格(#gridap)上没有选定的行,我们可以使用 jqmHide() 隐藏表单模式。
然后,我使用您的解决方案来显示alertcap。
Cool, tks Oleg!!!
BTW, I came with another(but not beautifull) solution:
** This is a aftershowform action.
If we do not have a selected row on the main grid(#gridap), we hide the form modal with jqmHide().
Then, I use your solution to show the alertcap.