Source
* Enable or disable table rows sorting according to rows count. At least 2 rows should exists to be able
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* @var CView $this
*/
?>
<script type="text/javascript">
jQuery(function($) {
var editableTable = function(elm, tmpl) {
var table = $(elm),
row_template = new Template($(tmpl).html()),
insert_point = table.find('tbody tr[data-insert-point]'),
row_index = 0,
table_row_class = 'editable_table_row';
table.sortable({
disabled: true,
items: 'tbody tr.sortable',
axis: 'y',
containment: 'parent',
cursor: 'grabbing',
handle: 'div.<?= ZBX_STYLE_DRAG_ICON ?>',
tolerance: 'pointer',
opacity: 0.6,
helper: function(e, ui) {
ui.children('td').each(function() {
$(this).width($(this).width());
});
return ui;
},
start: function(e, ui) {
// Fix placeholder not to change height while object is being dragged.
$(ui.placeholder).height($(ui.helper).height());
},
update: function() {
let i = 0;
table.find('.' + table_row_class).each(function() {
$(this).find('[name*="sortorder"]').val(i++);
});
}
});