Easygrid
Easygrid copied to clipboard
FilterForm
Hi there,
First thank you for your work. It is really helpful.
I am using the easygrid plugin with grails 2.3.1 and easygrid:1.6.9. It is fine, I have no problem to show my list. Now I would like to add a form on the top of the grid to add a more complex filter like for example "Where author or co author is me"
I m trying this simple code Here is how my controller is looking like (inspired from https://github.com/tudor-malene/Easygrid/issues/113):
def reportsGrid = {
domainClass Report
gridImpl 'jqgrid'
jqgrid {
sortname 'started'
sortorder 'desc'
}
enableFilter true
filterForm {
testrevision{
filterClosure { Filter filter ->
applyFilter(delegate, FilterOperatorsEnum.EQ, 'revision', filter.value)
}
}
}
...
}
Here is the code in my GSP file:
<grid:gridForm name="reports_table">
<input type="text" name="testrevision"/>
</grid:gridForm>
Here is a picture of the UI;
By the way, I got a problem with the tag gridForm (switch simple quote to "). I changed it to:
def gridForm = { attrs, body ->
if (attrs.id == null) {
attrs.id = attrs.name
}
out << "<form name='${attrs.id}' onsubmit=\""
if (attrs.function) {
out << "${attrs.function};"
}
out << "return easygrid.filterForm('${attrs.name}',this)"
out << "\">"
out << body()
out << "</form> "
}
Anyway now when I press enter on my filter input box, the following query is called: /report/reportsRows?testrevision=7. Hence the filter data is sent. But the result is wrong. The grid is just reloaded with the default rowNum 20 instead of the one set in my grid:
<grid:grid name="reports">
<grid:set width="1900" height="800" rowNum="50" altRows="true"/>
</grid:grid>
I set a breakpoint in FilterService and FilterFormService but it looks like they are never run. It might explain my problem. Any idea?
I think I found why the FilterFormService was not called. In EasygridDispatchService.groovy
static def services = [
GridImpl: 'gridImplService',
DS : 'dataSourceService',
AC : 'autocomplete.autocompleteService',
Export : 'export.exportService',
FFF : 'filterForm.filterFormService'
]
FFF should be FF.
Now FilterFormService is called but without success
Finally, I made it working. First be sure to change FFF to FF in EasygridDispatchService.groovy Second, here is the way to add a filter form:
filterForm {
fields {
'testauthor' {
label 'testlabel'
type 'text'
filterDataType String
filterClosure { Filter filter ->
or{
eq('username', filter.paramValue)
eq('coeditor', filter.paramValue)
}
}
}
}
}
Hi sebDK, thanks for using easygrid. I'm glad you made it work eventually.
The filterForm functionality hasn't unfortunately really gone beyond experimental, yet. I haven't had too much time to work on it.
Thanks for the fixes. I will add them to the next version.