Grails:动态地过滤Grails表中的数据 [英] Grails: filter data in a Grails table dynamically

查看:159
本文介绍了Grails:动态地过滤Grails表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,有一系列的事件,
我的班级的名字是Entry。



这是我桌子的图片



是西班牙文,但基本是相同的,所以它不应该是一个问题。
(过滤器的HTML代码还不是这么混乱,但它的工作原理)

这里是我在查找条目时得到的结果。



http://i45.tinypic.com /r1iexv.jpg

现在我的问题是我需要将结果显示/过滤到pic1中的同一个表中,所以它基本上就像应用过滤器的表更新。



如果您需要更多信息,请参阅我的旧问题的链接。感谢proflux!



大部分的搜索代码是有的,



任何帮助将不胜感激!

更新:

我有两个日期...
一个是事件发生的日期,另一个是lastUpdated,我认为这是上次修改事件的grails关键字。任何与筛选日期有关的帮助将不胜感激。

我需要从今天的日期开始显示第一个表格上的所有内容。如果我想找到过去的东西,我应该可以使用过滤器来找到它。



有关如何做到这一点的任何想法?
$ b

更新:

这里是我的list.gsp



http://i49.tinypic.com/291ksy1.png



这里是我的searchResults.gsp,其中包含了用于Ruta这个单词的过滤器

漂亮,漂亮,但日期过滤器不工作。



以下是控制器中不过滤日期的代码

  def searchResults = {
def entryCriteria = Entry.createCriteria()
def results = entryCriteria.list {
if(params?.proyectoRuta ){
ilike(proyectoRuta,%$ {params.proyectoRuta}%)
}

}
if(params?.day){
eq(fechaCambio,par ams.day)
}
render(view:'searchResults',model:['results':results])
}

正在过滤单词但不包含日期

preroyectoRuta 是标题, fechaCambio 是第一列中显示的日期。

更新:



好吧,这里是我的控制器:因为是很多的代码,我只会发布重要的defs

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


$ b def searchResults = {
def entryCriteria = Entry.createCriteria()
def results = entryCriteria.list {
if(params?.fechaCambioD& amp; params?.fechaCambioH){
between(fechaCambio,params.fechaCambioD,params.fechaCambioH)
} $ b $ (lastUpdated,params.lastUpdatedD,params.lastUpdatedH)
}
$ b之间的
($ params.lastUpdatedD& $ b if(params?.proyectoRutaN){
ilike(proyectoRuta,%$ {params.proyectoRutaN}%)
}
}
render(view: searchResults',模型:['结果':results,'proyectoRutaN':params?.proyectoRutaN,'fechaCambioD':params?.fechaCambioD,'fechaCambioH':params?.fechaCambioH,'lastUpdatedD':params?.lastUpdatedD,'lastUpdatedH':params?.lastUpdatedH] )
}
}

这里是searchResults.gsp

 < tbody> 

< td>< g:formatDate format =dd-MMMM-yyyydate =$ {it.fechaCambio}/>< / td>
< td>< b> $ {it.proyectoRuta}< / b>< / td>
< td> $ {it.summary}< / td>
< td>< g:formatDate format =dd-MMM-yyyy HH:mm zdate =$ {it.lastUpdated}/>< / td>
< td>
< g:actionSubmit class =editaraction =editvalue =$ {message(code:'default.button.editar.label',default: '& nbsp;& nbsp;& nbsp;')}/>< / span>
< span class =simple>< g:actionSubmit class =eliminaraction =deletevalue =$ {message(code:'default.button.eliminar.label' '& nbsp;& nbsp;& nbsp;')}onclick =return confirm('$ {message(code:'default.button.delete.confirm.message',default:'Esta seguro que desea Eliminar ? ')}'); />< /跨度>
< / g:表格>
< / td>
< / tr>
< / g:每个>
< / tbody>


解决方案

搜索标准...

 < html> 
< body>
< h1>搜索条件< / h1>

标题:< g:textField name =titlevalue =$ {title}/>
日期:< g:datePicker name =startTimevalue =$ {startTime}precision =day/>
< g:submitButton name =submitvalue =Search/>
< / g:表格>
< h1>搜寻结果< / h1>
< table>
< tr>
< th>标题< / th>
< th>开始日期< / th>
< / tr>
< tr>
< td> $ {it.title}< / td>
< td> $ {it.startTime}< / td>
< / tr>
< / g:每个>
< / table>
< / g:if>
< / body>
< / html>

然后为您的控制器关闭:

<$
$ def $ search
$ b $ def $ entry $ {
$ def $ {


$ def searchResults = {
def entryCriteria = Entry.createCriteria()
def results = entryCriteria.list {
if(params?.title){
ilike(title,%$ {params.title}%)

$ b $ render(view:'search',model:['results':results,
'title':params?.title,
'startTime' :params?.startTime])
}

这是我写的一个快速演示很快,但是从我给出的关于其他问题的信息和关于使用标准的 Grails参考文档查询,你应该能够弄清楚。如果遇到任何问题,请告知我们。



更新:这样你的条件之间的东西:

  def entryCriteria = Entry.createCriteria()
def results = entryCriteria.list {
if(params?.title){
ilike(title,%$ {params.title}%)
}
if(params?.day) (day,params.day,params.day + 1)
}
}

b $ b

I have a table, with a series of events, name of my class is Entry.

Here is a picture of my table

is in Spanish, but the basics are the same so it shouldn't be a problem. (the filter HTML code is not yet so its a mess but it works)

and here are the results that I get when I look for the entry.

http://i45.tinypic.com/r1iexv.jpg

Now my problem is that I need the results to be shown/filtered into the same table from pic1, so it would be basically like a table update applying the filters.

If you need more info here is the link to my old question. Thanks proflux!

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

Most of the search code is there,

Any help would be greatly appreciated!

UPDATE:

I have a problem filtering the dates though... I have two dates... One is the date the event is going to take place, and the other one is lastUpdated which I think is a keyword for grails for the last time you modified the Event. Any help related to filtering dates would be greatly appreciated.

I need to show everything on the first table starting from today's date. And if I want to find something from the past I should be able to use the filter to find it.

Any ideas on how to do this?

UPDATE:

So here is my list.gsp

http://i49.tinypic.com/291ksy1.png

and here is my searchResults.gsp with the filters applied for the word "Ruta"

So basically everything looks nice and pretty but the date filters are not working.

Here is the code in the controller that is not filtering the dates

def searchResults = { 
    def entryCriteria = Entry.createCriteria() 
    def results = entryCriteria.list { 
        if(params?.proyectoRuta) { 
            ilike("proyectoRuta","%${params.proyectoRuta}%")
            } 

        }
        if(params?.day) {
            eq("fechaCambio", params.day)
        } 
        render(view:'searchResults', model:['results':results]) 
} 

is filtering the word but not the dates

proyectoRuta would be the title and fechaCambio would be the date shown in the first column. I have not tried to filter the lastUpdated date yet.

UPDATE:

Ok so here is my controller: Since is a lot of code I will only post the important defs

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

} 

def searchResults = { 
    def entryCriteria = Entry.createCriteria() 
    def results = entryCriteria.list {
        if(params?.fechaCambioD && params?.fechaCambioH) { 
            between("fechaCambio", params.fechaCambioD, params.fechaCambioH) 
            } 

        if(params?.lastUpdatedD && params?.lastUpdatedH) { 
            between("lastUpdated", params.lastUpdatedD, params.lastUpdatedH) 
            }

        if(params?.proyectoRutaN) { 
            ilike("proyectoRuta","%${params.proyectoRutaN}%")
            }            
        }
        render(view:'searchResults', model:['results':results, 'proyectoRutaN':params?.proyectoRutaN, 'fechaCambioD':params?.fechaCambioD, 'fechaCambioH':params?.fechaCambioH, 'lastUpdatedD':params?.lastUpdatedD, 'lastUpdatedH':params?.lastUpdatedH]) 
} 
}

And here is the searchResults.gsp

<tbody>
                <g:each in="${results}">

                        <td><g:formatDate format="dd-MMMM-yyyy" date="${it.fechaCambio}" /></td>
                        <td><b>${it.proyectoRuta}</b></td>
                        <td>${it.summary}</td>
                        <td><g:formatDate format="dd-MMM-yyyy HH:mm z" date="${it.lastUpdated}" /></td>
                        <td>
                        <g:form>
                            <g:hiddenField name="id" value="${it?.id}" />
                            <span class="simple"><g:actionSubmit class="editar" action="edit" value="${message(code: 'default.button.editar.label', default: '&nbsp;&nbsp;&nbsp;')}" /></span>
                            <span class="simple"><g:actionSubmit class="eliminar" action="delete" value="${message(code: 'default.button.eliminar.label', default: '&nbsp;&nbsp;&nbsp;')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Esta seguro que desea Eliminar?')}');" /></span>
                        </g:form>
                        </td>
                    </tr>
                </g:each>
            </tbody>

解决方案

Try this using the same gsp for both the results and the search criteria...

<html>
<body>
    <h1>Search Criteria</h1>

    <g:form controller="entry" action="searchResults">
        Title: <g:textField name="title" value="${title}" />
        Date: <g:datePicker name="startTime" value="${startTime}" precision="day" />
        <g:submitButton name="submit" value="Search" />
    </g:form>
    <g:if test="${results}">
        <h1>Search Results</h1>
        <table>
            <tr>
                <th>Title</th>
                <th>Start Date</th>
            </tr>
            <g:each in="${results}">
                <tr>
                    <td>${it.title}</td>
                    <td>${it.startTime}</td>
                </tr>
            </g:each>
        </table>
    </g:if>
</body>
</html>

And then for your controller closures:

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

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

This is from a quick demo i wrote really quick, but from the info I gave you on the other question and the Grails Reference Documentation on using criteria queries, you should be able to figure it out. Let me know if you run into any problems.

Update:

Try something like this for your between criteria:

def entryCriteria = Entry.createCriteria()
def results = entryCriteria.list {
    if(params?.title) {
        ilike("title", "%${params.title}%")
    }
    if(params?.day) {
        between("day", params.day, params.day+1)
    }
}

这篇关于Grails:动态地过滤Grails表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆