replace value for any text

replace value for any text

impex09impex09 Posts: 45Questions: 20Answers: 0

Hi, I have a table with field "Level" so in my data base this value is numeric
1 = BEGIN
2 = MEDIUM
3 = EXPERT

so, in my frontend, when the field = 1, show BEGIN, when 2 show MEDIUM, etc

thank you

This question has an accepted answers - jump to answer

Answers

  • ntstravelntstravel Posts: 15Questions: 2Answers: 1
    Answer ✓

    Use a render function, so in your columns option:

    {
        data: 'level_id',
        // return the name of the level, given the id
        render: function (data, type, row) {
            switch(data) {
            case 1:
                return 'One';
                break;  
            case 2:
                return 'Two';
                break;
            default:
                return 'Error!';
            }
        },
    },
    

    This could be better done (not hard-coded like this) by passing your JS an associative array and looking up the result. But see if you can get it working like this for now.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I'd suggest also reading the orthogonal data manual page as you might want to order by the level_id rather than alphabetically.

    Allan

This discussion has been closed.