Replace 0 with No and 1 with Yes in Display

Replace 0 with No and 1 with Yes in Display

antoniocibantoniocib Posts: 277Questions: 62Answers: 1

As already mentioned in the title I would like to change 0 with No and 1 with Yes I have seen a bit around but I have not arrived at any solution I have found only this but it does not work

    {
        "data": "hub_na",
        orderable:false,
        searchable:false,

        render: function ( data, type, row ) {
                if ( $(data.hub_na === 1) ) {
                    var i = "YES";
                    return i;
                }
                else {
                    var i = "NO";
                    return i;
                }
            }
    },

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923
    Answer ✓

    You have a couple problems with the if statement: if ( $(data.hub_na === 1) ) {. The columns.render docs explain that the data parameter is the data for the column. Instead of data.hub_na use data. Also the $( .. ) is a jQuery method and shouldn't be in the if statement. Your if should like like this:

    if ( data === 1 ) {
    

    Also to increase the efficiency of the render function you can eliminate the assignment statements to reduce the number of overall statements. Something like this:

         render: function ( data, type, row ) {
                if ( data === 1 ) {
                    return "YES";
                }
                else {
                    return "NO";;
                }
            }
    

    Kevin

This discussion has been closed.