Search code examples
javascriptcsstwitter-bootstrapbootstrap-table

JS Bootstrap table to display boolean values as YES and NO instead 1 and 0


I have bootstrap table which fetches data from mysql db where I am having Boolean values which I want to display as YES or NO instead of 1 or 0 in my bootstrap table. My JS bootstrap table code

var $table = $('#table');
$table.bootstrapTable({
    url: 'list-user.php',
    search: true,
    pagination: true,
    buttonsClass: 'primary',
    showFooter: true,
    minimumCountColumns: 2,
    columns: [{
        field: 'num',
        title: '#',
        sortable: true,
    }, {
        field: 'first',
        title: 'Available',
        sortable: true,

    },],

});

I am a learner, tried various online solutions but couldn't make it work.


Solution

  • Use the formatter function - for example

    function formatYesNo(value,row,index){
      return value==0 ? 'No' : 'Yes';
    
    }
    

    Define your column formatter like this:

    formatter: formatYesNo,

    See this JSFiddle