Skip to content

Instantly share code, notes, and snippets.

@KeenthemesHub
Last active February 3, 2019 02:25
Show Gist options
  • Save KeenthemesHub/2be2b94c972d989c7a6c7ca23ca336a5 to your computer and use it in GitHub Desktop.
Save KeenthemesHub/2be2b94c972d989c7a6c7ca23ca336a5 to your computer and use it in GitHub Desktop.
'use strict';
// Class definition
var DatatableItems = function() {
// Private functions
// basic demo
var createTable = function() {
// var arrayOfObjects = [{"id":28,"Title":"Sweden"}, {"id":56,"Title":"USA"}, {"id":89,"Title":"England"}];
DatatableItems.datatable = $('.k_datatable').KDatatable({
// datasource definition
data: {
type: 'remote',
source: 'https://keenthemes.com/keen/themes/themes/keen/dist/preview/inc/api/datatables/demos/default.php',
pageSize: 50,
},
// layout definition
layout: {
theme: 'default', // datatable theme
class: '', // custom wrapper class
scroll: false, // enable/disable datatable scroll both horizontal and vertical when needed.
footer: false, // display/hide footer
},
// column sorting
sortable: true,
pagination: true,
search: {
input: $('#generalSearch'),
},
// columns definition
columns: [
{
field: 'id',
title: '#',
width: 20,
type: 'number',
selector: {
class: 'k-checkbox--solid k-checkbox--brand',
},
textAlign: 'center',
}, {
field: 'first_name',
title: 'title',
template: function(row) {
return '<a title="Edit Quantity" class="btn btn-sm btn-clean btn-icon btn-icon-md editQtyBtn"><i class="la la-edit"></i></a><input type="text" class="editQtyTxt" style="width:50px;display:none;" value="' +
row.first_name + '" /><span class="editQtyLbl">' + row.first_name + '</span>';
},
},
],
});
$('#k_form_status').on('change', function() {
datatable.search($(this).val().toLowerCase(), 'status');
});
$('#k_form_type').on('change', function() {
datatable.search($(this).val().toLowerCase(), 'type');
});
$('#k_form_status,#k_form_type').selectpicker();
}; // close createTable
return {
// public functions
init: function() {
createTable();
},
getRowData: function(row) {
return $(row).closest('tr').data('obj');
},
bindButtons: function() {
console.log('on init');
DatatableItems.datatable.on('click', '.editQtyBtn', function(event) {
console.log(DatatableItems.getRowData(this));
});
},
};
}();
jQuery(document).ready(function() {
DatatableItems.init();
DatatableItems.datatable.on('k-datatable--on-init', DatatableItems.bindButtons);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment