include space in search filter

include space in search filter

lawnder00lawnder00 Posts: 7Questions: 4Answers: 0

I have this code but i can't do a search filter with space or comma

$(document).ready(function () {
    oDtable = $('#exc').dataTable({
        "scrollX": true,
        "scrollY": 300,
        "oSearch": { "bSmart": false, "bRegex": true },
        "processing": true,
        "serverSide": true,
        "ajax": "/ajax/getJSONResultsForDT?table=eventos&primaryKey=id",
        "columns": [
            {"data": 'nombre'},
            {"data": 'descripcion'},
            {"data": 'fecha_inicio'},
            {"data": 'fecha_fin'},
            {"data": "created_by"},
            {"data": "updated_by"},
            {"data": null}, //6 y 7
            {"data": null}
        ],
        "columnDefs": [
            {
                "targets": [6],
                "orderable": false,
                "render": function (data) {
                    $id = data.id;

                    return '<button class="btn btn-default" data-toggle="modal" data-target="#edit-modal">Edit</button>';
                }
            },
            {
                "targets": [7],
                "orderable": false,
                "render": function (data) {
                    return '<a class="btn btn-danger" data-fancybox-type="iframe">' + 'Delete' + '</a>';
                }
            }],
        "bPaginate": true,
        "sPaginationType": "full_numbers",
    });  
});

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    "serverSide": true,

    It is up to your server-side script (/ajax/getJSONResultsForDT?table=eventos&primaryKey=id) how filtering is done since you've enabled server-side processing. If there is a filtering problem, then the issue is in that script.

    Allan

  • lawnder00lawnder00 Posts: 7Questions: 4Answers: 0
    edited November 2014

    This is my filter

    //------------

    static function filter ( $request, $columns, &$bindings )
    {
    $globalSearch = array();
    $columnSearch = array();
    $dtColumns = Datatables_SSP::pluck( $columns, 'dt' );

        if ( isset($request['search']) && $request['search']['value'] != '' ) {
            $str = $request['search']['value'];
    
            for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
                $requestColumn = $request['columns'][$i];
                $columnIdx = array_search( $requestColumn['data'], $dtColumns );
                $column = $columns[ $columnIdx ];
    
                if ( $requestColumn['searchable'] == 'true' ) {
                    $binding = Datatables_SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                    $globalSearch[] = "`".$column['db']."` LIKE ".$binding;
                }
            }
        }
    
        // Individual column filtering
        for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
            $requestColumn = $request['columns'][$i];
            $columnIdx = array_search( $requestColumn['data'], $dtColumns );
            $column = $columns[ $columnIdx ];
    
            $str = $requestColumn['search']['value'];
    
            if ( $requestColumn['searchable'] == 'true' &&
             $str != '' ) {
                $binding = Datatables_SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                $columnSearch[] = "`".$column['db']."` LIKE ".$binding;
            }
        }
    
        // Combine the filters into a single string
        $where = '';
    
        if ( count( $globalSearch ) ) {
            $where = '('.implode(' OR ', $globalSearch).')';
        }
    
        if ( count( $columnSearch ) ) {
            $where = $where === '' ?
                implode(' AND ', $columnSearch) :
                $where .' AND '. implode(' AND ', $columnSearch);
        }
    
        if ( $where !== '' ) {
            $where = 'WHERE '.$where;
        }
    
        return $where;
    }
    
This discussion has been closed.