How to modify or exclude a filter in a select in edit mode

How to modify or exclude a filter in a select in edit mode

GargiucnGargiucn Posts: 109Questions: 30Answers: 0

I have a filter in php that I would like to exclude in edit mode:

    Field::inst( 'assegnazioni.ass_idban' ) 
        ->options( Options::inst()      
        ->table( 'bandi' )
            ->value( 'ban_id' )
            ->label( 'ban_descr' ) 
            ->order( 'ban_descr ASC' )
            ->where( function ($q) {
how to? ---->if ( !isset( $_POST['editmode'] ) ) {
                    $q->where( 'bandi.ban_stop', 'NOW()', '>=', false );
                }
                $q->where( 'bandi.ban_id', '1', '!=' );
            } )     
        )

In editor I use the "Refreshing data before editing" mode...

    $.fn.dataTable.ext.buttons.editRefresh = {
        extend: 'edit',
        text: 'Modifica',
        action: function (e, dt, node, config) {
            var chiuso = (dt.rows( { selected: true } )
                .data().pluck('contratti').pluck('con_chiuso')).join('');   
            if ( chiuso == 1 ){
                $('#modalAlert .modal-body').html('<b>Contratto chiuso!</b>')
                $('#modalAlert').modal('show')
                $('#modalAlert .btn-ok').on('click', function(e){
                    $('#modalAlert').modal('hide')
                } );
            }else{          
                this.processing( true );
                // Get currently selected row ids
                var selectedRows = dt.rows({selected:true}).ids();
                var that = this;
                // Ajax request to refresh the data for those ids
                $.ajax( {
                    url: "php/table-assegnazioni.php",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        refresh: 'rows',
                        ids: selectedRows.toArray().join(','),
                    },
                    success: function ( json ) {
                        // Update the rows we get data back for
                        for ( var i=0 ; i<json.data.length ; i++ ) {
                            dt.row( '#'+json.data[i].DT_RowId ).data( json.data[i] );
                        }
                        dt.draw(false);
                        // Trigger the original edit button's action
                        $.fn.dataTable.ext.buttons.edit.action.call(that, e, dt, node, config);
                    }
                } );
            }   
        }   
    };      

How can i do to exclude the filter?
Thanks for your help,
Giuseppe

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,982Questions: 87Answers: 421
    edited April 2022 Answer ✓

    Ciao Giuseppe,

    when Editor reads the data it doesn't know what the user is going to do next. Will she do nothing, "create", "edit" or "delete" a record? Hence Editor cannot do what you would like it to do on the server.

    But client side you can filter the options read from the server, e.g. on "preOpen" depending on the user's action. That should be no problem.

    Just search for "preOpen" in the docs and also for "update" to update the options depending on user action.
    Here you are:
    https://editor.datatables.net/reference/api/field().update()
    https://editor.datatables.net/reference/event/preOpen

    Roland

Sign In or Register to comment.