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

dataTable Can't show more than 10 rows in table

Cha-Lee Chew
1#
Cha-Lee Chew Published in 2018-01-13 01:40:46Z

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>
MichaelT
2#
MichaelT Reply to 2018-01-15 11:51:28Z

PilotController.list(..) returns 10 Entries if no max is given, but you don't set the max, anything else cannot happen.

And You commented pagination out, so there is no way to get the follwing entries.

Cha-Lee Chew
3#
Cha-Lee Chew Reply to 2018-01-24 00:08:44Z

Found the solution to this problem,

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

All you need to do is remove: Math.min(max ?: 10, 100) So your code should look like this

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

Hope this helps you in future if any of you are facing the same problem.

Kam rabwa

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO