LeftJoin restricted : in editor

LeftJoin restricted : in editor

nervusdmnervusdm Posts: 9Questions: 4Answers: 0
edited June 2022 in Free community support

Hey guys,
Based on this example, is there a way to do this ?

~~Table:
~~

Name Country City
Jean France Paris
John USA New York

For this example, Country CANT change. Jean is in France, and John in USA.

City is a dropdown. But as you can imagine, the City "Paris" is based on "Jean" France, and John city is based on "USA".

So, I should not see "New york", in the dropdown for Jean (France).

Anyway to do this ?

I read about join statement, this is great, but in my case, I need a bit more.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    This means you need different options for each record in your data table. Editor doesn't support this because you can only load one set of options for every field for all records using Editor's options instance.

    Hence you need to make your own ajax call to the server to retrieve the contextual options and update the respective "select" field. Alternatively you can load all possible "cities" as options using Editor's options instance and then filter the presentable options client side.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    The dependent() method can help here. If the options need to change dependent on another value, it can trigger an Ajax call to get the options needed. There is a blog post with an example and details on how this can be done.

    Allan

  • nervusdmnervusdm Posts: 9Questions: 4Answers: 0

    Thanks for the dependant api.
    I must doing something wrong sadly, since it gives me a infinite loop ajax call about it.
    (change dropdown, then new ajax call...etc)

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    If you can show me the code, I can take a look. At a guess I would say that the dependent action is triggering a change in the options of the field that triggered the dependent action - hence the infinite loop.

    Allan

  • nervusdmnervusdm Posts: 9Questions: 4Answers: 0

    Still looking for it... It must be someting quite simple...

    Here is the front code, I look for it.
    Thanks,

    <table id='hs_lit' class="display">
    <thead>
    <tr>
        <th>Nom</th>
        <th>Date de naissance</th>
        <th>Statut</th>
        <th>Chambre</th>
    
        <th>Etablissement</th>
    </tr>
    </thead>
    </table>
    
    <script>
    (function($){
    
    
    $(document).ready(function() {
    
    
        $('#hs_lit').on( 'click', 'tbody td', function (e) {
            editor.inline( this );
        } );
        var editor = new $.fn.dataTable.Editor( {
            ajax: '{$url_projet}/rha/m_resident/updateData/',
            table: '#hs_lit',
            idSrc:  'lit_id',
            formOptions: {
                main: {
                    scope: 'cell' // Allow multi-row editing with cell selection
                },
            },
            fields: [
                {
                    "label": "Nom:",
                    "name": "lit_occupant"
                },
                {
                    "label": "Date de naissance:",
                    "name": "lit_date_naissance",
                    "type": "datetime",
                    "format": "YYYY-MM-DD",
                },
                {
                    "label": "Statut:",
                    "name": "lit_statut",
                    "type": "select",
                    "options": [
                        "",
                        "mort",
                        'disabled'
                    ]
                },
    
                {
                    "label": "Chambre:",
                    "name": "lit_id_chambre",
                    "type": "select",
    
                },
                
         
            ]
        } );
       editor.dependent( 'lit_id_chambre', '{$url_projet}/rha/m_resident/getChambre/' );
        var table = $('#hs_lit').DataTable( {
            dom: 'Bfrtip',
            ajax: '{$url_projet}/rha/m_resident/getData/',
            columns: [
                {
                    "data": "lit_occupant"
                },
                {
                    "data": "lit_date_naissance"
                },
                {
                    "data": "lit_statut"
                },
                {
                    "data": "chambre_nom",
                    'editField':'lit_id_chambre'
                },
                {
                    "data": "int_raisonsociale",
                },
    
                
            ],
            select: true,
            language: {
                url: '$url_projet/ro/views/js/datatable-fr.json'
            },
            keys: {
                editor:  editor
            },
            buttons: [
                { extend: 'excel', editor: editor },
                { extend: 'pdf', editor: editor },
    
                { extend: 'create', editor: editor },
                { extend: 'edit',   editor: editor },
                { extend: 'remove', editor: editor },
                "selectRows",
                "selectColumns",
                "selectCells",
                "selectNone"
            ]
        } );
    } );
    
    }(jQuery));
    </script>
    
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Thank you. And what does {$url_projet}/rha/m_resident/getChambre/ return?

    Allan

  • nervusdmnervusdm Posts: 9Questions: 4Answers: 0

    {"options":{"lit_id_chambre":[{"value":31813,"label":"5 "},{"value":31814,"label":"6 "},{"value":31815,"label":"7 "},{"value":35417,"label":"10 "},{"value":35418,"label":"11 "},{"value":35419,"label":"12 "},{"value":35420,"label":"14 "},{"value":35421,"label":"15 "},{"value":35422,"label":"16 "},{"value":35607,"label":"ABC1 "},{"value":35608,"label":"ABC2 "},{"value":35609,"label":"ABC3 "},{"value":53883,"label":"00f"},{"value":53884,"label":"002 "},{"value":53885,"label":"003 "},{"value":56465,"label":"MEDECINE GENERALE "},{"value":59231,"label":"CTEST "},{"value":59232,"label":"BTEST "},{"value":59233,"label":"ATEST "},{"value":72076,"label":"RESERVE RDC "},{"value":146698,"label":"LOCAL CONSIGNE AMS"},{"value":53886,"label":"101 "},{"value":53887,"label":"102 "},{"value":53888,"label":"103 "},{"value":56282,"label":"101 "},{"value":56283,"label":"102 "},{"value":56284,"label":"103 "},{"value":66912,"label":"161 "},{"value":72118,"label":"LOCAL STOCKAGE ETAGE 1 "},{"value":31808,"label":"2 "},{"value":31810,"label":"003"},{"value":31811,"label":"4 "},{"value":31833,"label":"1 "},{"value":34328,"label":"002 "},{"value":34329,"label":"003 "},{"value":38810,"label":"02 "},{"value":38811,"label":"03 "},{"value":38812,"label":"01 "},{"value":38813,"label":"202 "},{"value":38814,"label":"201 "},{"value":38815,"label":"203 "},{"value":38816,"label":"01 "},{"value":46620,"label":"004 "},{"value":46621,"label":"002 "},{"value":46622,"label":"003 "},{"value":53889,"label":"201 "},{"value":53890,"label":"202 "},{"value":53891,"label":"203 "},{"value":55078,"label":"206 "},{"value":56464,"label":"104"},{"value":85701,"label":"001"},{"value":85702,"label":"002"},{"value":85703,"label":"003"},{"value":85704,"label":"004"},{"value":31817,"label":"422 "},{"value":31818,"label":"423 "},{"value":31819,"label":"424 "},{"value":31821,"label":"421 "},{"value":35390,"label":"001P "},{"value":35391,"label":"002 "},{"value":35392,"label":"003 "},{"value":35393,"label":"004 "},{"value":35394,"label":"001"},{"value":35989,"label":"002 "},{"value":35990,"label":"003 "},{"value":35991,"label":"004 "},{"value":35992,"label":"005 "},{"value":46623,"label":"001 PORTE "},{"value":46624,"label":"001 FENETRE !"},{"value":56148,"label":"401 "},{"value":56149,"label":"402 "},{"value":56150,"label":"404 "},{"value":56151,"label":"403 "},{"value":56152,"label":"410 "},{"value":56153,"label":"405 "},{"value":56154,"label":"407 "},{"value":56155,"label":"408 "},{"value":56156,"label":"406 "},{"value":56157,"label":"409 "},{"value":56454,"label":"501 "},{"value":56455,"label":"502 "},{"value":56456,"label":"503 "},{"value":56457,"label":"504 "},{"value":56458,"label":"505 "},{"value":56459,"label":"506 "},{"value":69927,"label":"1087 "},{"value":60640,"label":"601 "},{"value":60641,"label":"602 "},{"value":60642,"label":"603 "},{"value":60643,"label":"604 "},{"value":60644,"label":"605 "},{"value":67099,"label":"602 "},{"value":67100,"label":"603 "},{"value":67101,"label":"604 "},{"value":67102,"label":"601 "},{"value":67866,"label":"BABA "},{"value":71919,"label":"602 "},{"value":71920,"label":"601 "},{"value":71921,"label":"603 "},{"value":71922,"label":"604 "},{"value":76056,"label":"602 "},{"value":76057,"label":"604 "},{"value":76058,"label":"603 "},{"value":76059,"label":"601 "},{"value":77312,"label":"TESTB "},{"value":77313,"label":"TESTC "},{"value":78862,"label":"601 "},{"value":78863,"label":"602 "},{"value":78864,"label":"603 "},{"value":78865,"label":"603 "},{"value":78866,"label":"601 "},{"value":78867,"label":"602 "},{"value":94785,"label":"603"},{"value":94786,"label":"601"},{"value":94787,"label":"602"},{"value":133922,"label":"601"},{"value":133923,"label":"602"},{"value":158570,"label":"603"},{"value":158571,"label":"602"},{"value":158572,"label":"601"},{"value":158573,"label":"605"},{"value":158574,"label":"604"},{"value":72113,"label":"703 "},{"value":72114,"label":"701 "},{"value":72115,"label":"705 "},{"value":72116,"label":"704 "},{"value":72117,"label":"702 "},{"value":75371,"label":"701 "},{"value":75372,"label":"702 "},{"value":76052,"label":"701 "},{"value":76053,"label":"703 "},{"value":76054,"label":"702 "},{"value":76055,"label":"704 "},{"value":87899,"label":"701"},{"value":87900,"label":"703"},{"value":87901,"label":"702"},{"value":89610,"label":"701"},{"value":89611,"label":"702"},{"value":95452,"label":"701"},{"value":95453,"label":"702"},{"value":95454,"label":"703"},{"value":95455,"label":"704"},{"value":133918,"label":"701"},{"value":133919,"label":"703"},{"value":133920,"label":"702"},{"value":133921,"label":"704"}]}}

  • nervusdmnervusdm Posts: 9Questions: 4Answers: 0

    ooooooh I got it !

    In fact, I have to use
    editor.dependent( 'lit_id_chambre'

    On an other field.

Sign In or Register to comment.