diff --git a/templates/base/components/datatable/layout.ready.js.twig b/templates/base/components/datatable/layout.ready.js.twig index 30cce83bc5..c42feb3b0a 100644 --- a/templates/base/components/datatable/layout.ready.js.twig +++ b/templates/base/components/datatable/layout.ready.js.twig @@ -329,4 +329,15 @@ if ($('#datatable_dlg_{{ oUIBlock.GetId() }}').hasClass('itop-datatable')) { $('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings('destroy'); } -$('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings($aOptions); \ No newline at end of file +$('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings($aOptions); + +if(window.ResizeObserver){ + let oTable{{ sListIDForVarSuffix }}ResizeTimeout = null; + const oTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){ + clearTimeout(oTable{{ sListIDForVarSuffix }}ResizeTimeout); + oTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){ + $('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust(); + }, 120); + }); + oTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]); +} \ No newline at end of file diff --git a/templates/base/components/datatable/static/formtable/layout.ready.js.twig b/templates/base/components/datatable/static/formtable/layout.ready.js.twig index 7791df3356..08a68880db 100644 --- a/templates/base/components/datatable/static/formtable/layout.ready.js.twig +++ b/templates/base/components/datatable/static/formtable/layout.ready.js.twig @@ -1,4 +1,7 @@ -var table{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }} = $('#{{ oUIBlock.GetId() }}').DataTable({ +{% set sListId = oUIBlock.GetId() %} +{% set sListIDForVarSuffix = ('' ~ sListId)|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %} + +var table{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ language: { emptyTable: "{{ 'UI:Message:EmptyList:UseAdd'|dict_s }}" }, @@ -23,5 +26,16 @@ var table{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ {% endif %} }); if ($('#{{ oUIBlock.GetId() }}').find('thead').is(':visible')) { - table{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER')) }}.columns.adjust().draw(); + table{{ sListIDForVarSuffix }}.columns.adjust().draw(); } + +if(window.ResizeObserver){ + let oFromTable{{ sListIDForVarSuffix }}ResizeTimeout = null; + const oFromTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){ + clearTimeout(oFromTable{{ sListIDForVarSuffix }}ResizeTimeout); + oFromTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){ + $('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust(); + }, 120); + }); + oFromTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]); +} \ No newline at end of file diff --git a/templates/base/components/datatable/static/layout.ready.js.twig b/templates/base/components/datatable/static/layout.ready.js.twig index e9e092b817..c850e1f58d 100644 --- a/templates/base/components/datatable/static/layout.ready.js.twig +++ b/templates/base/components/datatable/static/layout.ready.js.twig @@ -1,6 +1,7 @@ {# @copyright Copyright (C) 2010-2021 Combodo SARL #} {# @license http://opensource.org/licenses/AGPL-3.0 #} - +{% set sListId = oUIBlock.GetId() %} +{% set sListIDForVarSuffix = ('' ~ sListId)|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %} {% if oUIBlock.GetOption("iPageSize") is not empty %} {% set iPageSize = oUIBlock.GetOption("iPageSize") %} {% else %} @@ -58,4 +59,15 @@ $('#{{ oUIBlock.GetId() }}').DataTable({ }, {% endfor %} ] -}); \ No newline at end of file +}); + +if(window.ResizeObserver){ + let oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout = null; + const oStaticTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){ + clearTimeout(oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout); + oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){ + $('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust(); + }, 120); + }); + oStaticTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]); +} \ No newline at end of file