Changing Column Value

Changing Column Value

raisoncoraisonco Posts: 17Questions: 5Answers: 0

I want to display a different value to that stored in the database in the datatable.

For example if I have 'merged' in the DB then I want to display 'Merged Infrastructure'.

I currently use:

            {
                "data": "schedule_items.component"
            }

To get the database values. How could I amend the output?

For example:

if (schedule_items.component == 'merged') {
  $output = 'Merged Infrastructure''
} else if (.....

Thanks!

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948

    The columns.render option is used to change the displayed values. There is an example here:
    https://datatables.net/examples/advanced_init/column_render.html

    Kevin

  • raisoncoraisonco Posts: 17Questions: 5Answers: 0

    Thanks for the help. In case this helps others, here is how I coded it in the end:

    {
                    "data": "schedule_items.component",
                    "render": function ( data, type, row ) {
    
                        switch (data) {
                            case 'merged':
                                return 'Merged Item';
                                break;
                            case 'generic':
                                return 'Generic Item';
                                break;
                            case 'keynote':
                                return 'Keynote Item';
                                break;
                            default:
                                return data;
                        }
                    }
                }
    
This discussion has been closed.