[英]Grails with JqGrid inline edit with List()
I am working on setting up JqGrid with Grails and have in-line editing working. 我正在使用Grails设置JqGrid并进行内联编辑。 I have a drop-down box appear when the user selects a specific cell. 当用户选择特定的单元格时,会出现一个下拉框。
I want to populate this drop-down list from a table but am having trouble connecting the pieces together. 我想从表中填充此下拉列表,但是将各个部分连接在一起时遇到麻烦。 Here is the code i have so far... 这是我到目前为止的代码...
$(document).ready(function() {
jQuery("#task_list").jqGrid({
...
colModel:[
{name:'foo', editable:true, edittype:'select', editOptions:{values: ${com.project.inf.Domain.list()}}},
...
The ${com.project.inf.Domain.list()} creates a list of comma-delimited items, which I want to be displayed as options in the drop-down. $ {com.project.inf.Domain.list()}创建一个用逗号分隔的项目列表,我希望这些项目在下拉菜单中显示为选项。 However, it seems editOptions only accepts name:value pairs. 但是,似乎editOptions仅接受name:value对。 Is there a simple way to re-format the List() so it is accepted? 有没有一种简单的方法可以重新格式化List()使其被接受?
Thanks for the help! 谢谢您的帮助!
Yo lo resolví asi: 您的回复:
View: 视图:
{name:'listaDinamica',width:90, editable: true, editrules:required:true},edittype:'select', {name:'listaDinamica',宽度:90,可编辑:true,editrules:required:true},edittype:'select',
editoptions:{value:'${slcustomer}'}}, editoptions:{值:'$ {slcustomer}'}},
Controller: 控制器:
class TablaModeloController { TablaModeloController类{
TablaModeloService tms=new TablaModeloService()
def slcustomer= tms.llenaClientes()
def sl=Customer.list()
def index() {}
... ...
Service: 服务:
class TablaModeloService { TablaModeloService类{
def llenaClientes(){ def llenaClientes(){
def clientes='' def clientes =''
Customer.list().each{ Customer.list()。每个{
clientes+=it.id+":"+it.firstName+";" clientes + = it.id +“:” + it.firstName +“;”
} }
clientes=clientes[0..-2] clientes = clientes [0 ..- 2]
return clientes } 返回客户}
} }
Trabaja perfecto Trabaja perfecto
After some experimentation and reading of tutorials, I found the solution to this problem. 经过一些实验和阅读教程,我找到了解决此问题的方法。 I had to create a custom controller action and use the "dataUrl" option to use it as follows: 我必须创建一个自定义控制器操作,并使用“ dataUrl”选项来按如下方式使用它:
{name:'foo', width:100, editable:true, edittype:'select',
editoptions: {dataUrl:'${createLink(controller:"bar",action:"listAsSelect")}'}}
With the following as the listAsSelect action in the "bar" controller: 将以下内容作为“栏”控制器中的listAsSelect动作:
def listAsSelect={
def lst = Bar.findAll()
StringBuffer buf = new StringBuffer("<select>")
lst.each{
buf.append("<option value=\"${it.id}\">")
buf.append(it.toString())
buf.append("</option>")
}
buf.append("</select>")
render buf.toString()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.