YADCF 0/1 to yes/no and back again (with SSP)

YADCF 0/1 to yes/no and back again (with SSP)

losttheplotlosttheplot Posts: 10Questions: 2Answers: 0

I realise this isn't a yadcf forum but I'm wondering if anyone can help me as I try to get to grips with this great plugin (for a great plugin). I have a table column with ones and zeros which I am changing in my table to a styled yes or no indicator as follows:

'formatter' => function($d, $row) { 
    return $d ? '<span class="ind-green">yes</span>' : '<span class="ind-red">no</span>';
}

I am configuring yadcf as follows so that it offers a select filter of 'yes' or 'no':

{ column_number: 8, column_data_type: 'html' },

However, the values 'yes' and 'no' are being passed back to the server for filtering on a column with ones and zeros! Is there any way to configure yadcf so that it will pass back the values one or zero for the search query, please?

Answers

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    Hi,

    Notice the usage of data attribute in showcase for the third column int the first table . you can pass one type of values while displaying the other one...

  • losttheplotlosttheplot Posts: 10Questions: 2Answers: 0

    Thank you Daniel. My problem is not needing to differentiate what is displayed in the table cells with what is shown in the select element (your plugin does this just fine due to the html parsing), but in needing to send back data (e.g. '1') that is different to both the table cell (e.g. 'yes' inside a span element) and the selector element (e.g. 'yes'). I shall look at your suggestion in more depth tomorrow, thanks.

  • losttheplotlosttheplot Posts: 10Questions: 2Answers: 0

    I'm sure there are existing mechanisms within DataTables and/or yadcf to do the required mapping, but I'm finding the whole 'orthogonal data/renderers/data/whatever' thang very confusing on Day One of working with these plugins - as good as they are (I'm not complaining). So in the meantime I've done the mapping within the filter() function of ssp.class.php thus:

    // returned search values for 'subscribed' are yes/no, so we need to map these to 1/0.
    if ($column['db'] == 'cus_sub' && $str == 'no') { 
        $str = '0';
    } elseif ($column['db'] == 'cus_sub' && $str == 'yes') { 
        $str = '1';
    }
    

    I'm sure there are better ways to do this, but just in case there aren't, I'm posting this as a solution, pending someone explaining the correct way to do the mapping.

This discussion has been closed.