Easygrid icon indicating copy to clipboard operation
Easygrid copied to clipboard

FilterForm

Open sebDK opened this issue 10 years ago • 3 comments

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;

image

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?

sebDK avatar Dec 11 '14 09:12 sebDK

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

sebDK avatar Dec 11 '14 12:12 sebDK

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)
                        }
                    }
                }
             }
        }

sebDK avatar Dec 15 '14 07:12 sebDK

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.

tudor-malene avatar Feb 07 '15 11:02 tudor-malene