fields: [ {type: "datatable", .... EDIT VALUE

fields: [ {type: "datatable", .... EDIT VALUE

marianidiegomarianidiego Posts: 54Questions: 17Answers: 1

I'm this editor:

                        discountEditor = new $.fn.dataTable.Editor( {
                            serverSide:     true,
                            ajax: {
                                url: "dist/cont/tpl_lista_clients/clients_discount.php",
                                type: 'POST',
                                data: function ( d ) {
                                    d.csrf_token = "<?=$csrf1?>";
                                    d.clients_id = rowData.clients.clients_id;
                                }
                            },
                            table: "#discount",
                            fields: [
                                {
                                    label:          "Sconto:",
                                    name:           "clients_discounts.discount",
                                }, 
                                {
                                    label:          "Prodotto:",
                                    name:           "clients_discounts.product_id",
                                    type:           "datatable",
                                    config: {
                                        dom:        'Btf',
                                        info:       false
                                    }
                                }, 
                                {
                                    label:          "Fornitore:",
                                    name:           "clients_discounts.supplier_id",
                                    type:           "select",
                                }, 
                                {
                                    label:          "Categoria:",
                                    name:           "clients_discounts.category_id",
                                    type:           "select",

                                }
                            ]
                        } );

This table should save the discounts.... IT WORKS!!! Only if it is opened to edit a table ({ extend: 'edit', editor: discountEditor },) row, the value of “clients_discounts.product_id” is not loaded. Why? How can I fix this?

The table, it's not very "normal," I wouldn't want that to be the problem.

                        discountTable = $('#discount').DataTable({      
                            "language": {   "url": "<?=$ADMIN['lng']->t('DATATABLES', 'i18n');?>" },
                            "dom":          'Bt',
                            info:           false,
                            serverSide:     false,
                            select: {
                                            info: false
                            },
                            ajax: {
                                url: "dist/cont/tpl_lista_clients/clients_discount.php",
                                type: 'POST',
                                data: function ( d ) {
                                    d.csrf_token = "<?=$csrf1?>";
                                    d.clients_id = rowData.clients.clients_id;
                                }
                            },      
                            columns: [                  
                                { 
                                    title:  'Sconto',
                                    data:   'clients_discounts.discount',
                                    render: function (data, type, row, meta) {
                                        return data + "%";
                                    },
                                    attr:   { type: "number" }
                                },
                                {
                                    title:  'Per',
                                    data:   'clients_discounts.clients_discounts_id',
                                    render: function (data, type, row, meta) {

                                        // Sconto Generido
                                        if( row.clients_discounts.product_id == null && 
                                            row.clients_discounts.supplier_id == null && 
                                            row.clients_discounts.category_id == null)
                                            {
                                                return "Generico, su tutto il catalogo";
                                            } 

                                        // Sconto solo per un prodotto
                                        if( row.clients_discounts.supplier_id == null && 
                                            row.clients_discounts.category_id == null )
                                            {
                                                return "Solo per il prodotto " + row.products.name +
                                                    " (" + row.products.art_id_u + ")";
                                            }

                                        // Sconto per un fornitore
                                        if( row.clients_discounts.product_id == null && 
                                            row.clients_discounts.category_id == null )
                                            {
                                                return "Solo per il fornitore " + row.supplier.name +
                                                    " (" + row.supplier.acronym + ")";
                                            }

                                        // Sconto per una categoria
                                        if( row.clients_discounts.product_id == null && 
                                            row.clients_discounts.supplier_id == null )
                                            {
                                                return "Solo per la categoria " + row.category_view.concat;
                                            }

                                        // Per tutti gli altri casi
                                        let returntext='';
                                        if(row.clients_discounts.product_id != null)
                                            returntext += row.products.name + " (" + row.products.art_id_u + ")";

                                        if(row.clients_discounts.supplier_id != null){
                                            if(returntext.length > 0)
                                                returntext += " ; ";
                                            returntext +=  "Fornitore " + row.supplier.name +
                                            " (" + row.supplier.acronym + ")";
                                        }

                                        if(row.clients_discounts.category_id != null){
                                            if(returntext.length > 0)
                                                returntext += " ; ";
                                            returntext +=  "Categoria " + row.category_view.concat;
                                        }
                                        return returntext;

                                    }
                                }
                            ],


                            "searching":        false,
                            "paging":           false,
                            buttons: [
                                { extend: 'create', editor: discountEditor },
                                { extend: 'edit',   editor: discountEditor },
                                { extend: 'remove', editor: discountEditor }, 
                                'excel'
                            ],
                            "order":        [[ 0, "asc" ]],
                        });

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Can you show me the data being loaded into the DataTable please? Specifically I'm interested to see the values of clients_discounts.product_id and the options that are being loaded for that field.

    Even better would be a link to the page showing the issue so I can debug it. If you can't make the link public in this forum, you can PM me by clicking my forum user name and then "Send message".

    Allan

  • rf1234rf1234 Posts: 2,988Questions: 87Answers: 421
    edited November 20

    I found this:

    here: https://editor.datatables.net/reference/field/datatable

    Then I also see that "serverSide" is enabled in the above Editor and disabled in the above Data Table. I would turn "serverSide" off in both cases and try again.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    edited November 20

    That's a good point, but serverSide: true, at the top level of the Editor configuration object will have no effect. It isn't a parameter name Editor looks for and it will be ignored (I missed that it was on line 2 earlier - it should be removed as redundant).

    The configuration for the DataTable field is just:

                type:           "datatable",
                config: {
                    dom:        'Btf',
                    info:       false
                }
    

    So I don't think it is a server-side processing issue here. More likely the DataTables field's value isn't aligning with the field value.

    Allan

Sign In or Register to comment.