n1crack / datatables

Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.
https://datatables.ozdemir.be/
MIT License
266 stars 89 forks source link

Which method adds optional parameters to the row? #77

Closed wesleydeveloper closed 3 years ago

wesleydeveloper commented 3 years ago

I would like to use the DT_RowId but I tried using the add method and it didn't work.

n1crack commented 3 years ago

it worked like this. I added the column. And specified the columns in javascript code as well.

    $path = dirname(__DIR__).'/database/Chinook_Sqlite_AutoIncrementPKs.sqlite';

    $dt = new Datatables(new SQLite($path));

    $dt->query('Select TrackId, Name, UnitPrice from Track');

    $dt->add('DT_RowId', function($data) {
        return 'row_' . $data['TrackId'];
    });

    echo $dt->generate();
     $(document).ready(function () {
            $('#example').dataTable({
                "serverSide": true,
                "responsive": true,
                "columns": [
                    {"data": "TrackId"},
                    {"data": "Name"},
                    {"data": "UnitPrice"}
                ],
                "ajax": "ajax/basic.php"
            });
        });