<section class="panel">
    <header class="panel-heading clearfix panel-theame">
        Suppliers

        <div class="pull-right">
            <a class="ad-btn" onclick="loadPopupModal('suppliers/create','Add New Supplier','lg')">
                + Add Supplier
            </a>
        </div>
    </header>

    <div class="panel-body">
        <table class="table table-bordered" id="tbl_Suppliers">
            <thead>
                <tr>
                    <th>SI No</th>
                    <th>Supplier Name</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>File</th>
                </tr>
            </thead>
        </table>
    </div>
</section>

<script>
$(document).ready(function(){

    var table = $('#tbl_Suppliers').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: "<?php echo Yii::app()->createUrl('suppliers/GetList'); ?>",
            type: "POST"
        },
        fnCreatedRow: function(nRow){
            $(nRow).addClass("context-menu");
        },
        fnRowCallback: function(nRow, aData){
            AddContextMenu(nRow, aData);
        }
    });

});




function AddContextMenu(row, datas){

    $(row).contextMenu({
        selector: 'td',

        items: {

            "edit": {
                name: "Edit",
                callback: function(){
                    loadPopupModal(
                        "suppliers/create&id=" + datas[5].id,
                        "Edit Supplier",
                        "lg"
                    );
                }
            },

            "disable": {
                name: (datas[5].status == "Y") ? "Disable" : "Enable",
                callback: function(){

                    $.post(
                        $('#liveSite').val() + "index.php?r=suppliers/disable",
                        {id: datas[5].id},
                        function(){
                            reloadTable('#tbl_Suppliers');
                        }
                    );

                }
            }

        }
    });
}
</script>