Giter Site home page Giter Site logo

Enum datatype about easygrid HOT 11 CLOSED

tudor-malene avatar tudor-malene commented on August 24, 2024
Enum datatype

from easygrid.

Comments (11)

tudor-malene avatar tudor-malene commented on August 24, 2024

Hi John,

Thank you for using Easygrid.

For your scenario, you will have to write some code. There is no automatic way to do this ( yet ).

I would try something like this:

filterClosure{ Filter filter ->

    if(filter.paramValue){
        def sex
        switch(filter.paramValue.toLowerCase()){
            case ['m','male']:
                sex=SexEnum.MALE
                break
            case ['f','female']:
                sex=SexEnum.FEMALE
                break       
        }
        if(sex){    
            eq('sex', sex)
        }
    }
}

( this code is not tested)

Let me know how it goes.

Thank you.

from easygrid.

johnsylora avatar johnsylora commented on August 24, 2024

Hi Tudor, I tried your untested code above, and it works perfectly. Thank you so much.

However, using the code above if someone puts in a search term like Fem or Mal the code will set sex=null since it doesn't match any of the case options. In theory, no results should be returned, but with sex=null the field is ignored as a search term, and results are returned matching the other search fields like name(not shown) etc. I think the best solution would be to have the sex filter field be a select dropdown showing all the available valid enums. In this way, the user can only choose no enum, or a valid enum. What would be the best way to accomplish this? I noticed you have views/templates/easygrid/_filterFormRenderer.gsp. Would I have to modify this? The code inside there shows:

 <g:if test="${it.type == 'interval'}">
                        <div style='display:inline;'>
                            <g:field name="${it.name}.from" type="number"/>
                            <g:field name="${it.name}.to" type="number"/>
                        </div>
                    </g:if>
                    <g:else>
                        <g:field name="${it.name}" type="${it.type}"/>
                    </g:else>

Should I create a new type called Enum and try to display a select dropdown? An example for the select dropdown based on the enum type would be:

<g:select name="DomainName.sex" from="${SexEnum?.values()}" optionKey="key" value="${ObjectInstance?.sex?.name()}" noSelection="['': '']"/>

I would also like to apply this to the filters fields at the bottom of each column which has an enum datatype. In that case, would I apply the same process to the templates _dataTablesGridRenderer.gsp etc..? Thank you for all your help.

from easygrid.

pcornwell avatar pcornwell commented on August 24, 2024

I follow your bug follow ups Tudor, your project I have to say is great - we are using easy grid as we build a blood supply demand system. Frankly it rocks - thanks for your hard work

Pete

Sent from my iPad

On Dec 4, 2013, at 6:22 PM, johnsylora [email protected] wrote:

Hi Tudor, I tried your untested code above, and it works perfectly. Thank you so much.

However, using the code above if someone puts in a search term like Fem or Mal the code will set sex=null since it doesn't match any of the case options. In theory, no results should be returned, but with sex=null the field is ignored as a search term, and results are returned matching the other search fields like name(not shown) etc. I think the best solution would be to have the sex filter field be a select dropdown showing all the available valid enums. In this way, the user can only choose no enum, or a valid enum. What would be the best way to accomplish this? I noticed you have views/templates/easygrid/_filterFormRenderer.gsp. Would I have to modify this? The code inside there shows:

/g:if

/g:else
Should I create a new type called Enum and try to display a select dropdown like:

?

I would also like to apply this to the filters fields at the bottom of each column which has an enum datatype. In that case, would I apply the same process to the templates _dataTablesGridRenderer.gsp etc..


Reply to this email directly or view it on GitHub.

from easygrid.

tudor-malene avatar tudor-malene commented on August 24, 2024

Thank you for your kind words, Pete. :)
Don't hesitate to ask any questions or make suggestions.

from easygrid.

tudor-malene avatar tudor-malene commented on August 24, 2024

Hi John,

There's 2 ways you can accomplish this.

The easiest, is to change the filterClosure a little:


filterClosure{ Filter filter ->

    if(filter.paramValue){
        def sex
        switch(filter.paramValue.toLowerCase()){
            case ['m','male']:
                sex=SexEnum.MALE
                break
            case ['f','female']:
                sex=SexEnum.FEMALE
                break       
         }
        if(sex){    
            eq('sex', sex)
        }else{
            // when the input is wrong, apply here whatever condition you want
            isNull('sex')
        }
    }
} 

Regarding changing the search control to a selectBox:

  • one approach would be to change the _filterFormRenderer and add support for enum -like you said, or you could create your own customized filter form (a brand new template) - and only use the grid definition for the filter closures.
    ( the second option is more flexible , but not so DRY )
  • regarding the filter fields from datatables, yes, you will need to customize the template to change them. There's no support for doing this just by configuration, yet.
    I'm not really an expert with datatables, but basically, you can add support for whatever feature it has, just by modifying the template and/or by setting different properties.
    I, personally, haven't used datatables in any real project, but it has pretty good documentation.

from easygrid.

johnsylora avatar johnsylora commented on August 24, 2024

Hi Tudor, thank you for all your help. I do see on the datatables website they have support for the select column filtering: http://datatables.net/release-datatables/examples/api/multi_filter_select.html. I'll research this as well as the use of your other grids like jqGrid, Google visualization etc.. It's great you have a plugin that can access all these different types. But they are all confusing to get them to do exactly what you want with non-String datatypes like Enum, Integer etc.

from easygrid.

tudor-malene avatar tudor-malene commented on August 24, 2024

Hi,
I agree that customizing can be painful. But it's not easy at all to try to abstract away all the implementation details of the javascript grid implementations.
That is the reason why , on installing the plugin, the rendering templates are copied into the project.

From my experience, jqGrid is the easiest one to customize . I suggest you take a look at it.

Thanks,
Tudor

from easygrid.

johnsylora avatar johnsylora commented on August 24, 2024

Hi Tudor,

I followed your code for the filterClosure, and I was able to get the behavior I wanted. If they type in something like "fem" or "mal" which doesn't match any of the choices, it treats it like null and looks for anything in the sex column which is null ie (no entry). Since I have entries for all the rows under the sex column (every entry has MALE or FEMALE), it returns nothing. This makes sense since nothing matches "fem" or "mal". Of course, if I have null entries then they would show up. I guess the best is the Enum drop down select forcing the user to only enter valid Enum values and letting them know what the valid Enum value choices are. I'll look into the jqGrid like you suggest. Thank you for all your input.

from easygrid.

tudor-malene avatar tudor-malene commented on August 24, 2024

You can replace that isNull condition with anything. Could be : eq('sex', 'nothing').

from easygrid.

johnsylora avatar johnsylora commented on August 24, 2024

Hi Tudor, I refined the filterForm following your advice. The filterForm fields section in the controller ended up as follows:


            'sex' {
                    label 'Sex Filter'
                    type 'text'
                    filterClosure{ Filter filter ->
                        if(filter.paramValue){
                            def sex
                            switch(filter.paramValue.toLowerCase()){
                                case['m', 'male']:
                                    sex=SexEnum.MALE
                                    break
                                case['f', 'female']:
                                    sex=SexEnum.FEMALE
                                    break
                                case['null']:
                                    return isNull('sex') //finds null entries when user enters null in search field
                            }
                            if(sex){
                                eq('sex', sex) //finds MALE or FEMALE entries
                            }
                            else{
                            // when the input is wrong, show no entries
                                and{
                                    isNull('sex')
                                    isNotNull('sex')
                                }
                            }
                        }
                    }
                }

This should allow the user to input 'm' or 'male' for male, 'f' or 'female' for female and 'null' to find rows with no sex defined. If they enter 'fem' or 'mal' or anything else not recognized, the filterForm will return nothing. This behavior looks very good.

When I tried your code:

eq('sex', 'nothing') it threw an error that 'nothing' was not of type SexEnum. The way I found to return nothing was with the criteria:

and{
    isNull('sex')
    isNotNull('sex')
}

There may be a better way, but for now this works fine. Thank you so much for all your help.

from easygrid.

tudor-malene avatar tudor-malene commented on August 24, 2024

I'm glad it worked, I just wrote that as an example, didn't check it.

from easygrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.