Enable server side with editor php library

Enable server side with editor php library

Tech360Tech360 Posts: 6Questions: 5Answers: 0

I am using the editor php library but the serverside processing is not working with left join

Ordering columns, search or pagination is not working.

    $(document).ready(function() {
    
        editor = new $.fn.dataTable.Editor({
            ajax: {
                url: HOST+"/private/api/students/register.php",
                data: {
                    mode: "dt",
                },
                type: 'POST'
            },
            table: "#students-register",
            idSrc: 'students.id',
            fields: [
                {
                    label: "First Name",
                    name: "humans.fname"
                },
                {
                    label: "Surname",
                    name: "humans.sname"
                },
                {
                    label: "Address",
                    name: "human_details.address"
                },
                {
                    label: "Surname",
                    name: "human_details.city"
                },
                {
                    label: "Surname",
                    name: "human_details.state"
                },
                {
                    label: "Surname",
                    name: "human_details.zipcode"
                },
                {
                    label: "Surname",
                    name: "human_details.country"
                },
                {
                    name: "students.human",
                    type: "hidden"
                },
                {
                    name: "humans.id",
                    type: "hidden"
                }
            ],
            formOptions: {
                  bubble: {
                     submit: "allIfChanged"
                  }
              }
        });
    
        $('#students-register').on( 'click', 'tbody td:not(:first-child, :nth-child(4), :nth-child(5), :nth-child(6), :nth-child(7))', function (e) {
            editor.bubble( this );
        } );
    
        var table = $('#students-register').DataTable({
            dom: 'Brtip',
            ajax: {
                url: HOST+"/private/api/students/register.php",
                data: {
                    mode: "dt",
                    purp: "viewServer",
                    secret: secret,
                    human: human
                }
            },
            serverSide: true,
            columns: [
                {
                    name: "created",
                    data: "students.created"
                },
                {
                    name: "fname",
                    data: "humans.fname"
                },
                {
                    name: "sname",
                    data: "humans.sname"
                },
                {
                    name: "course",
                    data: "products.shortname"
                },
                {
                    name: "plan",
                    data: "versions.name"
                },
                {
                    name: "phone",
                    data: "phones.id"
                },
                {
                    name: "email",
                    data: "emails.id"
                },
                {
                    name: "address",
                    data: "human_details.address"
                },
                {
                    name: "city",
                    data: "human_details.city"
                },
                {
                    name: "state",
                    data: "human_details.state"
                },
                {
                    name: "zipcode",
                    data: "human_details.zipcode"
                },
                {
                    name: "country",
                    data: "human_details.country"
                }
            ],
            lengthChange: true,
            buttons: [
                'copy', 'csv', { extend: "edit",   editor: editor }
            ],
            select: true,
            order: [[ 0, "desc" ]],
            scrollX: true
        })
        
        // Apply the search
        table.columns().every( function () {
            var that = this
        
            $( 'input', this.footer() ).on( 'keyup change', function () {
                if ( that.search() !== this.value ) {
                    that
                        .search( this.value )
                        .draw()
                }
            })
        })
    })

With the following php code

    $editor = Editor::inst(
                    $db,
                    'students',
                    'students.id'
                )->fields(
                    Field::inst('humans.fname'),
                    Field::inst('humans.sname'),
                    Field::inst('phones.id'),
                    Field::inst('emails.id'),
                    Field::inst('versions.name'),
                    Field::inst('products.shortname'),
                    Field::inst('human_details.address'),
                    Field::inst('human_details.city'),
                    Field::inst('human_details.state'),
                    Field::inst('human_details.zipcode'),
                    Field::inst('human_details.country'),
                    Field::inst('students.created'),
                    Field::inst('humans.id'),
                    Field::inst('human_details.human'),
                    Field::inst('products.id'),
                    Field::inst('product_details.product'),
                    Field::inst('students.id'),
                    Field::inst('product_versions.product'),
                    Field::inst('versions.id')
                )
                    ->leftJoin('humans', 'students.human', '=', 'humans.id')
                    ->leftJoin('human_details', 'human_details.human', '=', 'humans.id')
                    ->leftJoin('emails', 'emails.human', '=', 'humans.id')
                    ->leftJoin('phones', 'phones.human', '=', 'humans.id')
                    ->leftJoin('product_versions', 'students.productv', '=', 'product_versions.id')
                    ->leftJoin('products', 'product_versions.product', '=', 'products.id')
                    ->leftJoin('product_details', 'product_details.product', '=', 'products.id')
                    ->leftJoin('versions', 'product_versions.version', '=', 'versions.id')
                    ->process($_POST)
                    ->json();

Can anyone help me with this one?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,506Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You need to add type: 'POST' to your DataTables initialisation for the Ajax object. You are using ->process($_POST), but DataTables will send a GET request by default.

    Allan

This discussion has been closed.