Welcome Guest, Not a member yet? Register   Sign In
Datatables and ORM Model
#1

Hi
I'm building a new ORM Model, which uses sqlsrv driver and works

PHP Code:
<?php
namespace App\Models;
use 
CodeIgniter\Model;
class 
MyModel extends Model
{
    protected 
$DBGroup 'sqlserver';
    protected 
$table 'project';
    protected 
$primaryKey 'idproject';
    protected 
$useAutoIncrement true;
    protected 
$returnType     'array';
    protected 
$useSoftDeletes true;
    protected 
$allowedFields = ['name''logo'];
    protected 
$useTimestamps false;


I load that model from a Library and return data to Controller

Code:
$data = json_encode($this->mymodel->findAll());

Now, I must use Datatables in the view, with serverSide=true and Ajax property pointing to Controller's url

The json format for Datatables is custom and must have additional fields (draw, recordsTotal, data, etc.)
https://datatables.net/manual/server-side

Code:
{
    "draw": 1,
    "recordsTotal": 57,
    "recordsFiltered": 57,
    "data": [
        [
            "Test1",
            "bla",
        ],
        [
            "Test2",
            "bla bla",
        ],
        ...
    ]
}

PS: I've already seen https://github.com/hermawanramadhan/Code...DataTables but it won't fit my needs in future

Does anyone have an example about how to build that custom json using the methods from ORM ?

Thanks a lot for any tip you can give me
Reply


Messages In This Thread
Datatables and ORM Model - by kabeza - 04-07-2022, 08:49 AM
RE: Datatables and ORM Model - by JustJohnQ - 04-07-2022, 11:38 PM
RE: Datatables and ORM Model - by kabeza - 04-08-2022, 04:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB