jquery.layout.resizeDataTable.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * UI Layout Callback: resizeDataTables
  3. *
  4. * DataTables plugin homepage: http://datatables.net
  5. *
  6. * This callback is used when a layout-pane contains 1 or more DataTable objects:
  7. * - when the DataTable is a 'child' of the pane; or
  8. * - when the DataTable is a 'descendant' of the pane - ie, inside other elements
  9. *
  10. * Assign this callback to the pane.onresize event.
  11. * If the layout is inside a tab-panel, _also_ bind to tabs.show()
  12. *
  13. * SAMPLE:
  14. * $("#elem").tabs({ show: $.layout.callbacks.resizeDataTables });
  15. * $("body").layout({ center__onresize: $.layout.callbacks.resizeDataTables });
  16. *
  17. * Version: 1.0 - 2012-07-06
  18. * Author: Robert Brower (atomofthought@yahoo.com)
  19. * @preserve jquery.layout.resizeDataTables-1.0.js
  20. */
  21. ;(function ($) {
  22. $.layout.callbacks.resizeDataTables = function (x, ui) {
  23. // may be called EITHER from layout-pane.onresize OR tabs.show
  24. var oPane = ui.jquery ? ui[0] : ui.panel;
  25. // cannot resize if the pane is currently closed or hidden
  26. if ( !$(oPane).is(":visible") ) return;
  27. // find all data tables inside this pane and resize them
  28. $( $.fn.dataTable.fnTables(true) ).each(function (i, table) {
  29. if ($.contains( oPane, table )) {
  30. $(table).dataTable().fnAdjustColumnSizing();
  31. }
  32. });
  33. };
  34. })( jQuery );