Home dataTable Can't show more than 10 rows in table
Reply: 0

dataTable Can't show more than 10 rows in table

user7062
1#
user7062 Published in May 22, 2018, 4:35 am

I've encountered a problem while trying to list the users in the table using dataTable.

So far everything is working fine but when I enter more than 10 users, it still shows me 10 rows and can't view more than 10 rows. I've been trying to use the show by 10 25 50 100 entries but still can't work.

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


This is the table that i use:

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

} );

This is my domain:

class Pilot {

    String fName
    String lName

    static constraints = {
    }
}

Here is the Controller:

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

And here is the list View:

<!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>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.395531 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO