Potential Glitch in ssp.class.php, pluck() function

Potential Glitch in ssp.class.php, pluck() function

jfadejfade Posts: 9Questions: 2Answers: 0

Hello! Long time user of DataTables here. After updating my copy of ssp.class.php to the latest (it was woefully out of date) users have reported some issues with searching. Certain columns were seemed to be ignored. After some debugging, I've determined that it's always column 0. I'm using server side processing in a very similar way to the examples. So, after defining my columns as the example shows:

$columns = array(
    array(
        'db' => 'id',
        'dt' => 'DT_RowId',
        'formatter' => function( $d, $row ) {
            // Technically a DOM id cannot start with an integer, so we prefix
            // a string. This can also be useful if you have multiple tables
            // to ensure that the id is unique with a different prefix
            return 'row_'.$d;
        }
    ),
    array( 'db' => 'first_name', 'dt' => 0 ),
    array( 'db' => 'last_name',  'dt' => 1 ),
    array( 'db' => 'position',   'dt' => 2 ),
    array( 'db' => 'office',     'dt' => 3 ),
    array(
        'db'        => 'start_date',
        'dt'        => 4,
        'formatter' => function( $d, $row ) {
            return date( 'jS M y', strtotime($d));
        }
    ),
    array(
        'db'        => 'salary',
        'dt'        => 5,
        'formatter' => function( $d, $row ) {
            return '$'.number_format($d);
        }
    )
);

I call SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns).

The error arises with the "pluck" function. In it, there's this check:

if(empty($a[$i][$prop])){

The problem is that, in the example above, the value of dt is 0, and this registers as empty, so this column is skipped over when building the search query. I've fixed it by changing it to:

if(empty($a[$i][$prop]) && ($a[$i][$prop]) !== 0){

This may not be ideal, but it's the workaround I've come up with. If there is a better way of handling this, I would of course welcome it. Otherwise, I hope this is helpful to someone else!

This question has an accepted answers - jump to answer

Answers

  • jfadejfade Posts: 9Questions: 2Answers: 0

    Whoops, let's tighten up the parenthesis a bit:

    if(empty($a[$i][$prop]) && ($a[$i][$prop] !== 0)){

    Sorry!

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Thank you! Fix committed.

    Allan

  • jfadejfade Posts: 9Questions: 2Answers: 0

    Ah, excellent! Many thanks to you for all your hard work!

This discussion has been closed.