Milk Admin

Introduction to ModelList

ModelList is the core of the dynamic table management system in Milk Manager. It allows you to easily create tables with advanced features like pagination, sorting, and filters, without writing complex HTML code.

What is a ModelList?

A ModelList is a class that manages the entire flow of writing a dynamic table, from database query to final HTML generation. It facilitates the creation of professional administrative interfaces with just a few lines of code.

How the Flow Works

The ModelList system automatically handles the entire flow of a dynamic table:

  1. Query Builder: Builds SQL queries based on request parameters
  2. Column Structure: Defines how to display data
  3. Pagination: Manages the division of results into pages
  4. Sorting: Allows sorting by any column
  5. Filters: Enables custom searches and filters
  6. HTML Output: Generates the final HTML code of the table

Basic Example: Simple Table

Here's how to create a basic table using ModelList directly without classes. Create a file inside modules called dynamic-table-example.module.php

<?php
namespace Modules\DynamicTableExample;
Route::set('dynamic_table_example', function() {
    // ModelList creation
    $model = new \App\Modellist\ModelList('#__users', 'table_users');
    
    // Query building with parameters from request
    $query = $model->queryFromRequest();
    
    // Query execution
    $rows = Get::db()->getResults(...$query->get());
    $total = Get::db()->getVar(...$query->getTotal());
  
    // Table generation
    $table_html = Get::themePlugin('table', [
        'info' => $model->getListStructure($rows, 'id'),
        'rows' => $rows,
        'page_info' => $page_info
    ]);
    if (($_REQUEST['page-output'] ?? '') == 'json') {
        Response::json(['html' => $table_html, 'success' => 'true', 'msg'=>'']);
    } else {
        Response::themePage('default','', $table_html);
    }
});

Documentation Structure

The ModelList documentation is organized into several sections:

Loading...