Select2 Filtered Row Won't Edit

Select2 Filtered Row Won't Edit

vincmeistervincmeister Posts: 136Questions: 36Answers: 4

Hi Allan,

I want to filter row using select2, then edit field value from selected row using editor edit button.
My problem is, the value won't updated

I load the ajax using

data: function ( d ) {
                        d.kode_distro = $("#SelectDistro").val();
                    }

where kode_distro is a selected value from select2

then on my php file

if ( ! isset($_POST['kode_distro']) || ! is_numeric($_POST['kode_distro']) ) {
        echo json_encode( [ "data" => [] ] );
    }
    else {
Editor::inst( $db, 'tr_receiving_detail' )
            ->pkey('tr_receiving_detail.id')
            ->fields(
                Field::inst( 'tr_receiving_head.tr_in_id' ),
                Field::inst( 'tr_receiving_detail.id' ),
                Field::inst( 'tr_receiving_detail.item_code' )
                    ->options( 'master_item', 'item_code', 'item_name', function ($q) {
                        $q->where( 'axapta', 'No', 'LIKE' );
                    }),
                Field::inst( 'master_item.item_name' ),
                Field::inst( 'tr_receiving_detail.quantity' ),
                Field::inst( 'tr_receiving_detail.customer_id' )
                    ->options( 'master_customer', 'id', 'customer_name' ),
                Field::inst( 'master_customer.customer_name' ),
                Field::inst( 'tr_receiving_detail.enduser_code' ),
                Field::inst( 'tr_receiving_detail.enduser_name' ),
                Field::inst( 'tr_receiving_detail.changes' ),
                Field::inst( 'tr_receiving_detail.dom_no' ),
                Field::inst( 'tr_receiving_detail.old_id' ),
                Field::inst( 'tr_receiving_detail.tr_in_id' )
            )
            ->leftJoin( 'tr_receiving_head', 'tr_receiving_head.tr_in_id', '=', 'tr_receiving_detail.tr_in_id' )
            ->leftJoin( 'master_item', 'master_item.item_code', '=', 'tr_receiving_detail.item_code' )
            ->leftJoin( 'master_customer', 'master_customer.id', '=', 'tr_receiving_detail.customer_id' )
            
            //where semua field lengkap (nama distro, nama bengkel & belum kirim)
            //kalo belum engkap keisi semua, harus pake update
            ->where ('tr_receiving_detail.psm_no','')
            ->where ('tr_receiving_detail.changes',0)
            ->where ( 'tr_receiving_detail.customer_id', '', '<>' )
            ->where ( 'tr_receiving_detail.enduser_code', '', '<>' )
            ->where ( 'tr_receiving_detail.enduser_name', '', '<>' )
            ->where( 'tr_receiving_detail.customer_id', $_POST['kode_distro'] )
            ->process($_POST)
            ->json();
    }

Live site here
Please advise, thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    $_POST['kode_distro']

    is currently be undefined when you submit the edit. You need to define that in the ajax.data option as well as the DataTables one (or modify the PHP to not attempt to use it for editing).

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    I try this, but no luck. The ajax.data is same as the ajax.data on datatables, which works good with select2 filter. Please advise

    var trDeliveryOrderEditor = new $.fn.dataTable.Editor( {
                    ajax: "function/tr-delivery-order.php",
                    table: '#tblDeliveryOrder',
                    data: function ( d ) {
                            var selected = trDeliveryOrderDataTable.row( { selected: true } );
                            if ( selected.any() ) {
                                //d.kode_distro = selected.data().tr_receiving_detail.customer_id;
                                d.kode_distro = $("#SelectDistro").val();
                            }
                        },
                    fields: [{
                                label: "Nomor DO:",
                                name: "tr_receiving_detail.dom_no",
                            }
                        ]
                } );
    
  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    If I pick "Lebron James" in the select2 list and then edit the first row in the table, this is what is sent to the server:

    action:edit
    data[row_39][tr_receiving_detail1][dom_no]:01
    

    I don't see the ajax.data option in the code:

                    ajax: "function/tr-delivery-order.php",
    

    Have a look at the ajax.data documentation for how it should work - it is nested in the ajax option.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    ah my bad, sorry Allan, i didn't change the live site, i change my localhost only.
    Now i put the same code as i wrote above, please take a look.

    thank you

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin
    Answer ✓

    I think you missed this part of my comment above:

    Have a look at the ajax.data documentation for how it should work - it is nested in the ajax option.

    Your data option isn't doing anything in the Editor configuration at the moment.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    hello Allan,

    thank you for the explanation, i create a different php file for the editor and it works.
    So i'm using 2 different php file for datatables and editor
    I'm not sure this is the correct / best solution, but it's ok for now, thanks again

    danny

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    Its a perfectly valid thing to do and it can be quite useful. Good to hear you have it working.

    Allan

This discussion has been closed.