$(function() {
  'use strict';

  $(function() {
    var table = $('#dataTableExample');
    if (!table.length) {
      return;
    }
    if (table.data('datatable') === 'off') {
      return;
    }

    var orderCol = parseInt(table.data('order-col'), 10);
    var orderDir = table.data('order-dir') || 'asc';
    var tableOptions = {
      "aLengthMenu": [
        [10, 30, 50, -1],
        [10, 30, 50, "All"]
      ],
      "iDisplayLength": 10,
      "language": {
        search: ""
      }
    };

    if (!isNaN(orderCol)) {
      tableOptions.order = [[orderCol, orderDir]];
    }

    table.DataTable(tableOptions);
    table.each(function() {
      var datatable = $(this);
      // SEARCH - Add the placeholder for Search and Turn this into in-line form control
      var search_input = datatable.closest('.dataTables_wrapper').find('div[id$=_filter] input');
      search_input.attr('placeholder', 'Search');
      search_input.removeClass('form-control-sm');
      // LENGTH - Inline-Form control
      var length_sel = datatable.closest('.dataTables_wrapper').find('div[id$=_length] select');
      length_sel.removeClass('form-control-sm');
    });
  });

});
