gestion des conditions

gestion des conditions

jmclamenjmclamen Posts: 15Questions: 8Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

with the searchbuilder plugin, we try to have only certain condition like "equals" or "not". Your example works. but my code dosen't works. why?

Answers

  • jmclamenjmclamen Posts: 15Questions: 8Answers: 0
    edited September 2021

    this is my code :

    <script type="text/javascript" language="javascript" class="init">
        
    
    
    var editor; // use a global for the submit and return data rendering in the examples
    
    /* ============ autres focntion ============ */
    (function() {
        var Editor = $.fn.dataTable.Editor;
        Editor.display.details = $.extend(true, {}, Editor.models.displayController, {
            init: function(editor) {
                // Setup the lightbox - we'll use it for new entries
                Editor.display.lightbox.init(editor);
    
                // No other setup needed
                return Editor.display.details;
            },
    
            open: function(editor, append, callback) {
                var table = $(editor.s.table).DataTable();
                var row = editor.s.modifier;
    
                // Close any rows which are already open
                Editor.display.details.close(editor);
    
                if (editor.mode() === 'create') {
                    // Its a new row. Use Editor's lightbox
                    Editor.display.lightbox.open(editor, append, callback);
                } else {
                    // Open the child row on the DataTable
                    table.row(row).child(append).show();
    
                    $(table.row(row).node()).addClass('shown');
    
                    if (callback) {
                        callback();
                    }
                }
            },
    
            close: function(editor, callback) {
                Editor.display.lightbox.close(editor, callback);
    
                var table = $(editor.s.table).DataTable();
    
                table.rows().every(function() {
                    if (this.child.isShown()) {
                        this.child.hide();
                        $(this.node()).removeClass('shown');
                    }
                });
    
                if (callback) {
                    callback();
                }
            }
        });
    })();
    

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • jmclamenjmclamen Posts: 15Questions: 8Answers: 0
    edited September 2021
    $(document).ready(function(){
        $("#bt_rp").css('background-color','#e83e8c');
        $("#bt_rp").css('color','#fff');
        $("#bt_investisseur").css('background-color','#bcbcbc');
        $("#bt_investisseur").css('color','#fff');
        
        
        
        editor = new $.fn.dataTable.Editor({
            ajax: "./controllers/E_lotgen.php",
            
            table: "#example",
            display: "details",
            template: '#customForm',
            fields: [ {
                    label: "idp:",
                    name: "qgpv_lot.id_programme",
                    type:  "select",
                     def: $('#id').val()
                },{
                    label: "Numéro:",
                    name: "qgpv_lot.numero"
                }, {
                    label: "Statut:",
                    name: "qgpv_lot.statut",
                    type:  "select",
                    options: [
                        { label: "LIBRE",    value: "LIBRE" },
                        { label: "RESERVE",   value: "RESERVE" },
                        { label: "GELE",   value: "GELE" },
                        { label: "ACTE",   value: "ACTE" }],
                    def: "LIBRE"
                }, {
                    label: "Type:",
                    name: "qgpv_lot.type",
                    type:  "select",
                    options: [
                        { label: "Choisissez type",    value: "0" },
                        { label: "1",  value: "1" },
                        { label: "2",  value: "2" },
                        { label: "3",  value: "3" },
                        { label: "4",  value: "4" },
                        { label: "5",  value: "5" }],
                    def: 0
                }, {
                    label: "Cage:",
                    name: "qgpv_lot.cage"
                }, {
                    label: "Exposition:",
                    name: "qgpv_lot.exposition",
                    type:  "select",
                    options: [
                        { label: "Choisissez Expo",    value: "0" },
                        { label: "N",    value: "N" },
                        { label: "S",   value: "S" },
                        { label: "E",   value: "E" },
                        { label: "O",   value: "O" },
                        { label: "NS",  value: "NS" },
                        { label: "NE",  value: "NE" },
                        { label: "NO",  value: "NO" },
                        { label: "EO",  value: "EO" } ],
                        
                    def: 0
                }, {
                    label: "Parking:",
                    name: "qgpv_lot.parking",
                    
                }, {
                    label: "Cave cellier:",
                    name: "qgpv_lot.cave",
                    
                },{
                    label: "traversant:",
                    name: "qgpv_lot.traversant",
                    type:  "select",
                    options: [
                        { label: "Non",    value: "Non" },
                        { label: "Oui",    value: "Oui" }],
                    def:"Non"   
                }, {
                    label: "Etage:",
                    name: "qgpv_lot.etage"
                },{
                    label: "Surf habitable:",
                    name: "qgpv_lot.surface_habitable",
                    
                }, {
                    label: "Surf Jardin:",
                    name: "qgpv_lot.surface_jardin",
                    
                }, {
                    label: "Surf exterieur:",
                    name: "qgpv_lot.surface_exterieur",
                    
                },{
                    label: "Prix actuel:",
                    name: "qgpv_lot.prix_tmp_actuel",
                    /* type: "mask", */
                    /* mask: "00000" */
                    /* type: "mask", */
                    
                },{
                    label: "Prix vendu Res:",
                    name: "qgpv_lot.prix_vendu",
                },{
                    label: "Prix annexe:",
                    name: "qgpv_lot.prix_annexe",
                },{
                    label: "FNO:",
                    name: "qgpv_lot.FNO",
                    type:  "select",
                    options: [
                        { label: "Non",    value: "Non" },
                        { label: "Oui",    value: "Oui" }],
                    def:"Non"   
                },{
                    label: "montant TMA offert:",
                    name: "qgpv_lot.montant_TMA_offerte",
                },{
                    label: "Remise:",
                    name: "qgpv_lot.remise",
                },{
                    label: "Vendeur:",
                    name: "qgpv_lot.vendeur",
                },{
                    label: "Ve-vi:",
                    name: "qgpv_lot.ve-vi",
                    type:  "select",
                    options: [
                        { label: "-",    value: "-" },
                        { label: "Interne",    value: "Interne" },
                        { label: "Externe",    value: "Externe" }],
                    def:"-" 
                },{
                    label: "Taux Ve-Vi:",
                    name: "qgpv_lot.taux"
                },{
                    label: "Hono_ve:",
                    name: "qgpv_lot.hono_ve",
                    type:'readonly'
                },{
                    label: "remise_totale:",
                    name: "qgpv_lot.remise_totale",
                },{
                    label: "Reservataire:",
                    name: "qgpv_lot.reservataire",
                },{
                    label: "date reservation:",
                    name: "qgpv_lot.date_reservation",
                },{
                    label: "Loyer Marché:",
                    name: "qgpv_lot.inv_loyer_marche",
                    
                },{
                    label: "dt crea:",
                    name: "qgpv_lot.datecrea",
                },{
                    label: "Attesta.:",
                    name: "qgpv_lot.attestation",
                    type:  "select",
                    options: [
                        { label: "-",    value: "-" },
                        { label: "En cours",   value: "En cours" },
                        { label: "Obtenu",   value: "Obtenu" },
                        { label: "Transmis",   value: "Transmis" }],
                    def:"-"
                },{
                    label: "Offre:",
                    name: "qgpv_lot.offre",
                    type:  "select",
                    options: [
                        { label: "-",    value: "-" },
                        { label: "En cours",   value: "En cours" },
                        { label: "Obtenu",   value: "Obtenu" },
                        { label: "Transmis",   value: "Transmis" }],
                    def:"-"
                },{
                    label: "Relance:",
                    name: "qgpv_lot.relance",
                    type:  "select",
                    options: [
                        { label: "-",    value: "-" },
                        { label: "R1",   value: "R1" },
                        { label: "R2",   value: "R2" },
                        { label: "R3",   value: "R3" }],
                    def:"-"
                },{
                    label: "Accord:",
                    name: "qgpv_lot.accord",
                    type:  "select",
                    options: [
                        { label: "-",    value: "-" },
                        { label: "En cours",   value: "En cours" },
                        { label: "Obtenu",   value: "Obtenu" },
                        { label: "Transmis",   value: "Transmis" }],
                    def:"-"
                },{
                    label: "TVA 5.5",
                    name: "qgpv_lot.tva55",
                    type:  "select",
                    options: [
                        { label: "Non",    value: "Non" },
                        { label: "Oui",    value: "Oui" }],
                    def:"Non"   
                },{
                    label: "PRIX TVA 5.5",
                    name: "qgpv_lot.prix_tmp_actuel_55",
                },{
                    label: "Dt mod:",
                    name: "qgpv_lot.datemodif",
                },{
                    label: "Prix M2:",
                    name: "prixm2",
                    type:'readonly'
                },{
                    label: "Surface pondéré:",
                    name: "qgpv_lot.inv_surface_pondere",
                    type:'readonly'
                },{
                    label: "Loyer pinel:",
                    name: "qgpv_lot.inv_loyer_pinel",
                    type:'readonly'
                },{
                    label: "Economie Impot:",
                    name: "qgpv_lot.inv_economie_impot2",
                    
                },{
                    label:"Effort Epargne Brut:",
                    name: "qgpv_simulation.effort_epargne",
                    type:'readonly'
                    
                },{
                    label: "Rentabilité brut:",
                    name: "qgpv_lot.inv_rentabilite_brut",
                    
                },{
                    label: "Mensualité:",
                    name: "qgpv_simulation.mensualite",
                    type:'readonly'
                    
                },{
                    label: "Taux mensualité:",
                    name: "qgpv_simulation.taux",
                    type:'readonly'
                    
                },{
                    label: "Duree credit en mois:",
                    name: "qgpv_simulation.duree",
                    type:'readonly'
                    
                },{
                    label: "Apport:",
                    name: "qgpv_simulation.apport",
                    type:'readonly'
                    
                    
                },{
                    label: "plafond de location par M2 ponderé:",
                    name: "plafd_loc_m2_pond",
                    type:'readonly'
                    
                    
                },{
                    label: "coeff zone:",
                    name: "qgpv_zone.coeff",
                    type:'readonly'
                    
                    
                },{
                    label: "Charges divers:",
                    name: "qgpv_simulation.charges_divers",
                    type:'readonly'
                    
                    
                }
            ]
        });
    
  • jmclamenjmclamen Posts: 15Questions: 8Answers: 0
    edited September 2021
        /*  ============== table =============== */
         
        /* var office=$('#office').val();
        var contenu_mail="London"; ?id="+$('#id').val()*/
        
        var table = $('#example').DataTable({
            /* dom: "QlBfrtip", */
            dom: "QBfrtip",/*Q=searchbuilder, l=lenght ligne,B=button, f=,r=,t=,i=,p=.*/
             language:{
            url: 'https://cdn.datatables.net/plug-ins/1.11.1/i18n/fr_fr.json'
            },
            iDisplayLength : 50,
            ajax: "./controllers/E_lotgen.php?id="+$('#id').val(),
            type : 'POST', 
            colReorder: true,
            searchBuilder: {
                columns: [1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18],
                 /* { "sType": "numeric" }, */
                conditions: {
                    string1: {
                      "=":{
                        conditionName: function (dt, i18n) {
                            return dt.i18n('searchBuilder.conditions.string.equals', i18n.conditions.string.equals);
                        },
                        init: $.fn.dataTable.Criteria.initSelect,
                        inputValue: $.fn.dataTable.Criteria.inputValueSelect,
                        isInputValid: $.fn.dataTable.Criteria.isInputValidSelect,
                        search: function (value, comparison) {
                            return value === comparison[0];
                        }
                      },
                      "!=":{
                        conditionName: function (dt, i18n) {
                            return dt.i18n('searchBuilder.conditions.string.not', i18n.conditions.string.not);
                        },
                        init: $.fn.dataTable.Criteria.initSelect,
                        inputValue: $.fn.dataTable.Criteria.inputValueSelect,
                        isInputValid: $.fn.dataTable.Criteria.isInputValidSelect,
                        search: function (value, comparison) {
                            return value != comparison[0];
                        }
                      
                      }
                    },
                    
            
            },
             preDefined: {
                    criteria:[
                        {
                            condition: '=',
                            data: 'Statut',
                            value: ['LIBRE']
                        },
                    ],
                    logic: 'AND'
                }   
        
            },   
            columnDefs:[
            { type: "num", targets: [4,6,8,9,10,11,12,13,15,16,17,18] }
            ,{searchBuilderType: 'string1',targets:[1,2,3,4]},{searchBuilderType: 'num1',targets:[0]},
            { "visible": false, targets:  [16,17,18]}
            ,{responsivePriority: 1, targets: [0,12] }
            ,{ responsivePriority: 10002, targets: [10,11,7] }
            ,{ responsivePriority: 10001, targets: [8,9,5] }
            /* ,{ responsivePriority: 2, targets: -2 } */
            ,{
            targets: [ 1, 2,3,4,5,6,7,8,9,10,11,16,17,18 ],
                createdCell: function (td, cellData, rowData, row, col) {
                    $(td).css('text-align', 'center');
                }   
                
            },{
                    targets: 4,
                    createdCell: function (td, cellData, rowData, row, col) {
                                /* if ( cellData < 1 ) { */
                                $(td).css('color', 'red')
                                //}
                                
                                /* if ( cellData > 100000 ) { */
                                $(td).css('font-weight', 'bold');
                                $(td).css('text-align', 'center');
                                
                                //}
                            }
                        }
            ],
            responsive: true, 
            columns: [
                {
                    className:      'details-control',
                    orderable:      false,
                    data:           null,
                    defaultContent: ''
                },
                { data: "conf_region.nomregion" },
                { data: "qgpv_programme.ville" },
                { data: "qgpv_programme.nomprogramme" },
                { data: "qgpv_lot.numero" },
                { data: "qgpv_lot.statut" },
                { data: "qgpv_lot.type" },
                { data: "qgpv_lot.exposition"},
                { data: "qgpv_lot.etage"},
                { data: "qgpv_lot.surface_habitable", render: $.fn.dataTable.render.number( ' ', ',', 2, '' )},
                { data: "qgpv_lot.surface_exterieur", render: $.fn.dataTable.render.number( ' ', ',', 2, '' )},
                { data: "qgpv_lot.parking"},
                { data: "qgpv_lot.cave"},
                { data: "qgpv_lot.tva55"},
                { data: "qgpv_lot.prix_annexe", render: $.fn.dataTable.render.number( ' ', ',', 0, '' )},
                { data: "qgpv_lot.prix_tmp_actuel", render: $.fn.dataTable.render.number( ' ', ',', 0, '' )}, 
                { data: "qgpv_simulation.effort_epargne", render: $.fn.dataTable.render.number( ' ', ',', 0, '' )},
                { data: "qgpv_simulation.mensualite", render: $.fn.dataTable.render.number( ' ', ',', 0, '' )},
                { data: "qgpv_lot.inv_rentabilite_brut", render: $.fn.dataTable.render.number( ' ', ',', 2, '' )},
            ],
            order: [[1, 'asc']],
            select: true,
            buttons: [
                
                { extend: "create", editor: editor } 
                ,{
                            extend: 'collection',
                            text: 'Export',
                            buttons: [
                                'copy',
                                'excel',
                                'csv',
                                'print'
                            ]
                }
                ,{
                    extend: 'pdfHtml5',
                    orientation: 'landscape',
                    pageSize: 'LEGAL'
                }/* ,{
                    text: 'Import CSV',
                    action: function () {
                        uploadEditor.create({
                            title: 'CSV file import'
                        });
                    }
                } */
            ],
             
            rowCallback: function ( row, data, index ) {
                $('td:first-child', row).attr('title', 'Click to edit');
                
                /* console.log('index:'+index ); */
                /* console.log('data:'+data[index] ); */
                /* console.log('row:'+row[index] ); */
                
                /* var d=row;
                for (var x in d) {
                        console.log("x="+x+"==>"+d[x]);
                        for (var y in d['qgpv_lot']) {
                        console.log("y="+y+"==>"+d['qgpv_lot'][y]);
                        }
                } */
                
                /* ---------- changement de titre en fonction de l'appel -------------- */
                /* alert("hello215"); */
                if ($('#id').val()==0)
                {
                $("#titrepage").text("Tous les lots de Quartus");
                }else{
                $("#titrepage").text("les lots du programme "+data['qgpv_programme']['ville']+" "+data['qgpv_programme']['nomprogramme']+" "+data['qgpv_programme']['code_postal']);
                }   
                
                /* ============ condition de bouton ============*/
                if ($('#role_id').val()==1){
                     table.button(0).enable();
                    /*table.button(1).enable();
                    table.button(4).enable(); */
                }else{
                    
                     table.button(0).disable();
                    /*table.button(1).disable();
                    table.button(4).disable(); */
                }               
                
            }
        });
        
    
     
    
      /* =========== sous tableau ============ */
     /* ======================================*/
        $('#example').on( 'click', 'td.details-control', function () {
            var tr = this.parentNode;
     
            if ( table.row( tr ).child.isShown() ) {
                editor.close();
            }
            else {
                if ($('#role_id').val()==1){
                    editor.edit(
                        tr,
                        'Edition du lot',
                        [
                            {
                                "className": "delete",
                                "label": "Supprimer ligne",
                                "fn": function () {
                                    // Close the edit display and delete the row immediately
                                    editor.close();
                                    editor.remove();//( tr, '', null, false )
                                    
                                    
                                    editor.submit();
                                }
                            }, {
                                "label": "Mettre à jour",
                                "fn": function () {
                                    editor.submit();
                                }
                            }/* ,{
                                extend: "create",
                                editor: editor,
                                formButtons: [
                                    'Create',
                                    { text: 'Cancel', action: function () { this.close(); } }
                                ]
                            } */
                        ]
                    );
                    
                    
                }else{
                    editor.edit(tr,'Edition du lot');
                    
                }       
          
        
                
            }
        });
        
        /* ============= fonction ============ */
            $("#DTE_Field_qgpv_lot-taux").change(function(){
            /* $(this).css("background-color", "#D6D6FF"); */
                alert("change");
            });
            
            function surf_pond_plaf(surf){
                var r=0;
                if(surf>16){
                    r=8
                }else{
                    r=surf/2;
                    
                }
            return r;//.toFixed(2)
                
            }   
        
        
        
        
            function pinel_plan_plafon(coeff){
                var r=coeff;
                if (coeff<0.8){r=0.8;}
                if (coeff>1.2){r=1.2;}
                return r;
            }   
            
            function economie_impot(prix,m2){
                var r=prix;
                var m=m2;
                var pm2=0;
                
                if (prix>300000){r=300000;}
                pm2=r/m2;
                
                if (pm2>5500){r=5500;}
                
                r=pm2*m2; /* calcul du prix */
            
                return r;
            }
            
            function calcul_effort_epargne(marche,pinel,credit,econimpot,charges_divers){
                var r=pinel;
                var ret=0;
                if (marche<pinel){r=marche;}
                if (marche==0){r=pinel;}
                ret=(credit-r-econimpot)+charges_divers;
                console.log("calcul_effort_epargne:"+ret);
                return ret;
            }
            
            function rentabilite_brut(marche,pinel,economens,prix){
                console.log("m:"+marche+",p:"+pinel+",e:"+economens+",p:"+prix);
                var r=pinel;
                var ret=0;
                if (marche<pinel){r=marche;}
                if (marche==0){r=pinel;}
                ret=((r+economens)*1200)/prix;
                console.log("m:"+ret);
                return ret;
            }
            
            /*  bouton rp et investissuer pour afficher les bonnes colonnes */
            $('a.toggle-vis').on( 'click', function (e) {
            e.preventDefault();
            /* alert("visibilite:"+$(this).attr('data-column-Display-on')+"/"+$(this).attr('data-column-Display-of')); */
            // Get the column API object
            var action = $(this).attr('data-action');
            //alert("affichage des colonnes pour la vision : "+action);
            var column13 = table.column('13');
            var column14 = table.column('14');
            var column16 = table.column('16');
            var column17 = table.column('17');
            var column18 = table.column('18');
            
                // Toggle the visibility
                if(action=="RP"){
                    $("#bt_rp").css('background-color','#e83e8c');
                    $("#bt_investisseur").css('background-color','#bcbcbc');
                    column13.visible(true);
                    column14.visible(true);
                    column16.visible(false);
                    column17.visible(false);
                    column18.visible(false);
                }else{
                    $("#bt_rp").css('background-color','#bcbcbc');
                    $("#bt_investisseur").css('background-color','#e83e8c');
                    column13.visible(false);
                    column14.visible(false);
                    column16.visible(true);
                    column17.visible(true);
                    column18.visible(true);
                }       
            
              
            });
        
        
        
    });
    </script>
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It's probably got something to do with the data, either some HTML in the response or something else that's breaking the match. If you are unable to link to your page, please could you post a line of the Ajax response for one of the records, and a search that doesn't match for that record.

    Colin

Sign In or Register to comment.