0

This is the table;

 <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Process</th>
        </tr>
    </thead>
</table>

and here is the javascript ;

 $(document).ready(function () {
        var table = $('#example').DataTable({
            "sPaginationType": "full_numbers",
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "ServerSideProcessor.aspx",
            "columnDefs": [{
                "targets": -1,
                "data": null,  
                "defaultContent": "<button type='button' class='btn btn-success'>PAY</button>"
            }]
        });

        $('#example tbody').on('click', 'button', function () {
            var data = table.row($(this).parents('tr')).data();
            alert(data[1] + " is recieved.");
        });
    });

What I need is create different type of buttons in "Process" coloumb, for example ;

"columnDefs": [{
                "targets": -1,
                "data": null,  
               if(data[5]=='1')
                "defaultContent": "<button type='button' class='btn btn-success'>PAY</button>"
               else
"defaultContent": "<button type='button' class='btn btn-warning'>UNPAID</button>"
            }]
        });

How can I accomplish that ? Thank you

1 Answer 1

1

Use render to define the output like this:

"render": function ( data, type, full) {
   if(full[5] == '1'){
        return "<button type='button' class='btn btn-success'>PAY</button>";
    }else{
        return "<button type='button' class='btn btn-warning'>UNPAID</button>";
    }
}

Here is a working jsfiddle DEMO. I've changed the condition to make it work with the dummy data, but you get the idea.

Sign up to request clarification or add additional context in comments.

1 Comment

That was exactly what I was looking for, thank you sir!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.