;(function ($, window, document, undefined) { // Load and build table and pagination based on current data state var loadTable = function($table) { params = {}; params[$table.data('ajaxTable').params.page] = $table.data('page'); params[$table.data('ajaxTable').params.sortColumn] = $table.data('sort-column'); params[$table.data('ajaxTable').params.sortDirection] = $table.data('sort-direction'); params[$table.data('ajaxTable').params.search] = $table.data('search'); var request = $.ajax({ url: $table.data('source'), data: $.extend({ format: 'json' }, params), type: 'GET', dataType: 'json' }); request.done(function(data) { buildRows($table, data.rows); buildPagination($table, data.pagination); }); }; // Build table rows var buildRows = function($table, rows) { var $tbody = $table.find('tbody'); $tbody.children().remove(); $.each(rows, function(i,row) { var $tr = $(''); $tbody.append($tr); $.each(row, function(k,v) { $tr.append('' + v + ''); }); }); }; // Build counts and simple pagination var buildPagination = function($table, pagination) { $td = $table.find('tfoot').find('td').first(); $td.children().remove(); if (pagination.total_count > pagination.count) { // Display current out of total record count if ($table.data('ajaxTable').text.count) { var $count = $('', { class: $table.data('ajaxTable').cssClasses.count }); $td.append($count); $count.html($table.data('ajaxTable').text.count.replace('{count}', pagination.count).replace('{total_count}', pagination.total_count)); } // Build pagination controls var pageCount = Math.ceil(pagination.total_count / pagination.per_page); var currentPage = $table.data('page'); var $ul = $('