dataTable表中不能显示10行以上

时间:2018-01-13 01:40:47

标签: grails

我在尝试使用dataTable列出表中的用户时遇到了问题。

到目前为止一切工作正常但是当我输入超过10个用户时,它仍然显示10行,并且不能查看超过10行。我一直试图通过10 25 50 100个条目来使用该节目,但仍然无法正常工作。

以下是我尝试使用的功能的屏幕截图:

Here is the screen shot of the function that i've been trying to use

这是我使用的表格:

$(document).ready(function() {
    $('table.dataTable').dataTable();

} );

这是我的域名:

class Pilot {

    String fName
    String lName

    static constraints = {
    }
}

这是控制器:

class PilotController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index() {
        redirect(action: "list", params: params)
    }

    def list(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        [pilotInstanceList: Pilot.list(params), pilotInstanceTotal: Pilot.count()]
    }

    def create() {
        [pilotInstance: new Pilot(params)]
    }

    def save() {
        def pilotInstance = new Pilot(params)
        if (!pilotInstance.save(flush: true)) {
            render(view: "create", model: [pilotInstance: pilotInstance])
            return
        }

        flash.message = message(code: 'default.created.message', args: [message(code: 'pilot.label', default: 'Pilot'), pilotInstance.id])
        redirect(action: "show", id: pilotInstance.id)
    }

    def show(Long id) {
        def pilotInstance = Pilot.get(id)
        if (!pilotInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "list")
            return
        }

        [pilotInstance: pilotInstance]
    }

    def edit(Long id) {
        def pilotInstance = Pilot.get(id)
        if (!pilotInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "list")
            return
        }

        [pilotInstance: pilotInstance]
    }

    def update(Long id, Long version) {
        def pilotInstance = Pilot.get(id)
        if (!pilotInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "list")
            return
        }

        if (version != null) {
            if (pilotInstance.version > version) {
                pilotInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                          [message(code: 'pilot.label', default: 'Pilot')] as Object[],
                          "Another user has updated this Pilot while you were editing")
                render(view: "edit", model: [pilotInstance: pilotInstance])
                return
            }
        }

        pilotInstance.properties = params

        if (!pilotInstance.save(flush: true)) {
            render(view: "edit", model: [pilotInstance: pilotInstance])
            return
        }

        flash.message = message(code: 'default.updated.message', args: [message(code: 'pilot.label', default: 'Pilot'), pilotInstance.id])
        redirect(action: "show", id: pilotInstance.id)
    }

    def delete(Long id) {
        def pilotInstance = Pilot.get(id)
        if (!pilotInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "list")
            return
        }

        try {
            pilotInstance.delete(flush: true)
            flash.message = message(code: 'default.deleted.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "list")
        }
        catch (DataIntegrityViolationException e) {
            flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'pilot.label', default: 'Pilot'), id])
            redirect(action: "show", id: id)
        }
    }
}

以下是列表视图:

<!DOCTYPE html>
<html>
    <head>
        <meta name="layout" content="bstheme">
        <g:set var="entityName" value="${message(code: 'pilot.label', default: 'Pilot')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="col-md-12">
            <div class="panel panel-custom">
        <!--<a href="#list-pilot" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>-->
        <div class="panel-heading">
            <g:message code="default.list.label" args="[entityName]" />

            <div class="panel-options">
                <a class="home" href="${createLink(uri: '/')}"><i class="glyphicon glyphicon-home"></i></a>
                <g:link class="create" action="create"><i class="glyphicon glyphicon-plus"></i></g:link>
            </div>
        </div>
        <div class="panel-body">
        <div id="list-pilot" class="content scaffold-list" role="main">
            <!--<h1><g:message code="default.list.label" args="[entityName]" /></h1>-->
            <g:if test="${flash.message}">
            <div class="message" role="status">${flash.message}</div>
            </g:if>
            <table class="dataTable table table-striped table-hover table-responsive">
                <thead>
                    <tr>

                        <g:sortableColumn property="fName" title="${message(code: 'pilot.fName.label', default: 'First Name')}" />

                        <g:sortableColumn property="lName" title="${message(code: 'pilot.lName.label', default: 'Last Name')}" />

                    </tr>
                </thead>
                <tbody>
                <g:each in="${pilotInstanceList}" status="i" var="pilotInstance">
                    <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

                        <td><g:link action="show" id="${pilotInstance.id}">${fieldValue(bean: pilotInstance, field: "fName")}</g:link></td>

                        <td>${fieldValue(bean: pilotInstance, field: "lName")}</td>

                    </tr>
                </g:each>
                </tbody>
            </table>
            <%-- <div class="pagination">
                <g:paginate total="${pilotInstanceTotal}" />
            </div> --%>
        </div>
    </div>
</div>
</div>
    </body>
</html>

2 个答案:

答案 0 :(得分:0)

找到解决此问题的方法,

def list(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        [pilotInstanceList: Pilot.list(params), pilotInstanceTotal: Pilot.count()]
    }

您需要做的就是删除:

Math.min(max ?: 10, 100)在控制器中,

所以你的代码应该是这样的

def list(Integer max) {
        params.max 
        [pilotInstanceList: Pilot.list(params), pilotInstanceTotal: Pilot.count()]
    }

希望如果您有任何人面临同样的问题,这将有助于您。

Kam rabwa

答案 1 :(得分:-1)

如果没有给出最大值,PilotController.list(..)会返回10个条目,但是你没有设置最大值,其他任何事情都不会发生。

你评论了分页,所以没有办法获得以下条目。