ready = function(){
  $('table.dataTable').each(function () {
    var table = $(this);

    var defaultDataTableSettings = {
      bProcessing: true,
      bPaginate: true,
      bServerSide: true,
      iDisplayLength: 10,
      aLengthMenu: [[10, 50, 100], ['10', '50', '100']],
      aaSorting: [[0, 'asc']],
      bFilter: true,
      bSort: true,
      sDom: 'rtlip',
      fnServerData: function (sSource, aoData, fnCallback) {
        $.getJSON(sSource, aoData, function (json) {
          fnCallback(json);
        });
      }
    };

    table.dataTable($.extend(defaultDataTableSettings, {
      sAjaxSource: table.data('source'),
      aaSorting: table.data('default-sort'),
      bFilter: table.data('filterable'),
      bSort: table.data('sortable')
    }));
  });
};

$(document).on('page:load', ready)
$(document).ready(ready);
