Using if or case statements to display returned data

Using if or case statements to display returned data

lsheckelllsheckell Posts: 2Questions: 1Answers: 0

I'm currently using Editor for a project I'm working on. I don't have a working example because at this point I'm not even sure how I would go about doing this.

I have a DB field named "status" that returns numeric values (1,2,3,4,5). In my PHP application, I have a switch statement to decipher the "human readable" value for this field based on the number returned from the database.

Example:

switch ($contact->status) {
case 0:
    $status = "Not Set";
    break;
case 1:
    $status = "1st call";
    break;
case 2:
    $status = "2nd call";
    break;
case 3:
    $status = "3rd call";
    break;
case 4:
    $status = "Reached";
    break;
case 5:
   $status = "Unreached";
   break;
default:
   $status = "Not Set";
   break;
}
echo $status;

This is of course using PHP, but I'm sure that something similar can be done with DataTables as well. Can someone point me in the right direction (via documentation or other source) for instruction on how to do something like this using Editor? Any help would be appreciated, thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Absolutely yes, this can be done with DataTables. Specifically the columns.render option is the one you want.

    Take a look at this example. It is a little simpler than your own since the Status column has only two states (1 or 0), but the same principle applies.

    Let me know if you have any questions about it.

    Regards,
    Allan

  • lsheckelllsheckell Posts: 2Questions: 1Answers: 0

    Awesome... thanks Allan!!

  • cerasellacerasella Posts: 2Questions: 1Answers: 0

    Another thank you from me! I've been searching for this answer all day yesterday. Why is the Datatable documentation so... wooden, I'll never understand... it's worse that php's...

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    @cerasella - Would certainly appreciate some feedback on how you think it can be improved!

    Allan

This discussion has been closed.