I have a bunch of data and I need a data filter using Grails

I’m trying to create a filter for my data so that other people can see it, say, I have a bunch of events, like a calendar, and I want to see everyone who has a name or a name with the word “Football.” I was trying to figure out how do it, but nothing works for me, I also tried using the filterPane plugin, but it didn’t work very well, and I prefer to write something myself and maybe upload it to the Grails plugins web page for future reference,

Any help would be greatly appreciated.

+3
source share
3 answers

If in a domain class try:

def matches = Book.findAllByTitleLike("wonderful")

/ :

def matches = Book.findAllByTitleILike("wonderful")

:

def books = ['Wonderful Tonight', 'Atlas Shrugged', 'A Tale of Two Cities']
def matches = books.findAll{it.indexOf("wonderful") > -1} // returns []
matches = books.findAll{it.indexOf("Wonderful") > -1} // returns ['Wonderful Tonight']
matches = books.findAll{it.toLowerCase().indexOf("wonderful") > -1} // returns ['Wonderful Tonight']

Update:

, , , .

, , , .

:

  • .
  • /

grails-app/views/entry/ search.gsp :

<g:form controller='entry' action='searchResults'>
   Entry Title: <g:textField name="title" value="${title}" />
   Entry Date: <g:datePicker name="day" value="${day}" precision="day" />
   <g:submitButton name="submit" value="Search" />
</g:form>

. grails-app/controller/ EntryController.groovy. , "grails create-Control Entry", EntryController.

:

def search = {
  render(view:'search')
}

def searchResults = {
  def entryCriteria = Entry.createCriteria()
  def results = entryCriteria.list {
    if(params?.title) {
      ilike{"title","%${params.title}%"
    }
    if(params?.day) {
      eq("eventDate", params.day)
    }
  }
  render(view:'searchResults', model:['results':results])
}

, searchResults.gsp grails-app/views/entry

<h1>Results</h1>
<g:each in=${results}>
  ${it}
</g:each>

, :

  • localhost: 8080/${appName}/entry/search, .
  • / , .
  • ,
  • , gsp .

, " " , , , . , , . .

, :

  • , , , .
  • ; , .
  • , searchResults, Grails, , . , - .
  • ; Entry , .

, . . searchResults :

def results = Entry.findByTitleILike(params?.title)

, .

!

+4

findAllWhere, . .

+1

The filter plugin meets your requirements.

+1
source

Source: https://habr.com/ru/post/1751267/


All Articles