<script>
"use strict";
// Class definition

var KTDatatableRemoteAjaxDemo = function() {
    // Private functions

    // basic demo
    var demo = function() {

        var datatable = $('#kt_datatable').KTDatatable({
            // datasource definition
            data: {
                type: 'remote',
                source: {
                    read: {
                        url: "<?=get_admin_path('download_category/ajax_list')?>",
                        // sample custom headers
                        // headers: {'x-my-custom-header': 'some value', 'x-test-header': 'the value'},
						params: {
						  <?=csrf_token()?>: '<?=csrf_hash()?>'
						},
                        map: function(raw) {
                            // sample data mapping
                            var dataSet = raw;
                            if (typeof raw.data !== 'undefined') {
                                dataSet = raw.data;
                            }
                            return dataSet;
                        },
                    },
                },
                pageSize: 10,				
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
            },			
            // layout definition
            layout: {
                scroll: false,
                footer: false,
				theme: 'default',
            },
			toolbar: {
				items:{
					pagination:{
						pageSizeSelect: [10, 20, 30, 40, 50],
					},
				},				
			},
            // column sorting
            sortable: true,

            pagination: true,

            search: {
				onEnter: false,
				delay: 600, // milliseconds
                input: $('#kt_datatable_search_query'),
                key: 'generalSearch'
            },

            // columns definition
            columns: [{
				field: 'RecordID',
                title: 'id',
				width: 120,
				type: 'number',
                textAlign: 'center',
            },{
                field: 'title',
                title: 'Title',
            },{   
                field: 'status',
                title: 'Status',
                // callback function support for column rendering
                template: function(row) {
                    var statusProp = {
                        'Active': {
                            'title': 'Active',
                            'class': ' label-light-success'
                        },
                        'Inactive': {
                            'title': 'Inactive',
                            'class': ' label-light-danger'
                        },
                    };
                    return '<span class="label font-weight-bold label-lg ' + statusProp[row.status].class + ' label-inline">' + statusProp[row.status].title + '</span>';
                },
            }, {
                field: 'Actions',
                title: 'Actions',
                sortable: false,
                width: 125,
                overflow: 'visible',
                autoHide: false,
                template: function(row) {
					var deleteUrl = "<?=get_admin_path('download_category/delete/')?>" + row.RecordID;
                    return '\
						<a href="<?=get_admin_path("download_category/edit/")?>' + row.RecordID + '" class="btn btn-sm btn-clean btn-icon mr-2" title="Edit details">\
                            <i class="fa fa-edit"></i>\
                        </a>\
                        <a href="javascript:;" onclick="deleteRecord(\''+deleteUrl+'\');" class="btn btn-sm btn-clean btn-icon" title="Delete">\
                            <i class="fa fa-trash" aria-hidden="true"></i>\
                        </a>\
                    ';
                },
            }],

        });

		$('#kt_datatable_search_status').on('change', function() {
            datatable.search($(this).val().toLowerCase(), 'status');
			//datatable.search("vishal", 'Mobile_No');
        });

        $('#kt_datatable_search_status, #kt_datatable_search_type').selectpicker();
    };

    return {
        // public functions
        init: function() {
            demo();
        },
    };
}();

jQuery(document).ready(function() {
    KTDatatableRemoteAjaxDemo.init();
});
</script>