Reputation: 1589
this seems really easy but have not been able to do it.
Currently I have an enum:
enum LocationCodes{
USA(3), Canada(4), Carribean(5), USPacific(6)
NANPCodeGroup(int value) {this.value = value}
private final int value
public int value() {return value}
}
And I have a jquery grid in my gsp that has a dropdown for searching
<!-- table tag will hold our grid -->
<table id="customer_list" class="scroll jqTable" cellpadding="0" cellspacing="0"></table>
<!-- pager will hold our paginator -->
<div id="customer_list_pager" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
/* when the page has finished loading.. execute the follow */
$(document).ready(function () {
jQuery("#customer_list").jqGrid({
url:'jq_customer_list',
datatype: "json",
colNames:['customer','location','id'],
colModel:[
{name:'customer'},
{name:'location',stype:'select', searchoptions:{value:':All;USA:USA;Canada:Canada;Carribean:Carribean;USPacific:USPacific;'}},
{name:'id', hidden:true}
],
rowNum:2,
rowList:[1,2,3,4],
pager: jQuery('#customer_list_pager'),
viewrecords: true,
gridview: true
});
$("#customer_list").jqGrid('filterToolbar',{autosearch:true});
});
</script>
For the location I would like to put in the enum values. Any thoughts? Thanks!
Upvotes: 0
Views: 1251
Reputation: 4636
This should give the list of enums separated by ';'
${LocationCodes?.values()?.collect{it.toString() + ':' + it.toString()}?.join(';')}
So you can try something like this:
searchoptions: {
value: ":All;${LocationCodes?.values()?.collect{it.toString() + ':' + it.toString()}?.join(';')}"
}
Double check the escaping of quotes, but it should work. :)
Upvotes: 1
Reputation: 171144
Does this work? (assuming it's a GSP)
{ name:'location',
stype:'select',
searchoptions:{ value:'":All;${LocationCodes.values().collect { "$it:${it.value()}" }.join(';')};"'}},
That should give you
':All;USA:3,Canada:4,Carribean:5,USPacific:6;'
But I've not tested it :-/
Upvotes: 0