We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32645
    • 377 Posts
    I’ve created a module which outputs a list/table which has a list of names/email address, but I don’t know how to get it to paginate?

    Is there a function like this "$modx->paginate($sql, $page, $offset, $limit=10)"

    If not, how do you do pagination in a module?

    $sql = 'SELECT * FROM tablename';
    $res = mysql_query($sql);
    while ( $row=mysql_fetch_array($result) )
    {				
    	$list .= '
    		<tr>
    			<td>'.$row['id'].'</td>
    			<td>'.$row['name'].'</td>
    			<td>'.$row['email'].'</td>			
    			<td><a href="index.php?a=112&id='.$this->config['module_id'].'&action=delete">Delete</a></td>
    		</tr>';
    } // wend
    


    I want to be able to paginate the above, but am not sure how to do it.

    Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The core Manager functions uses the DataGrid class (manager/includes/controls/datagrid.class.php). You can see how it’s used in manager/actions/user_management.static.php, at line 134. You invoke the datagrid after the query to retrieve your list from the database. It uses 20 items as the default page size, but this can be customized with a parameter when creating the object.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32645
        • 377 Posts
        Okay, thank you.