Add row group customization

This commit is contained in:
Robert Resch 2020-12-15 20:34:43 +00:00
parent 54e4d3217c
commit f7e3ded50f
No known key found for this signature in database
GPG Key ID: 5E3DFB30DC2833B6
6 changed files with 143 additions and 15 deletions

View File

@ -2008,3 +2008,12 @@ msgstr ""
msgid "Show on stock overview page" msgid "Show on stock overview page"
msgstr "" msgstr ""
msgid "None"
msgstr ""
msgid "Group by"
msgstr ""
msgid "Ingredient group"
msgstr ""

View File

@ -709,6 +709,45 @@ $.extend(true, $.fn.dataTable.defaults, {
{ {
column.search.search = ""; column.search.search = "";
}); });
var api = new $.fn.dataTable.Api(settings);
if (typeof api.rowGroup === "function")
{
var rowGroup = {
enable: api.rowGroup().enabled(),
};
if (api.rowGroup().enabled())
{
rowGroup.dataSrc = api.rowGroup().dataSrc()
}
data.rowGroup = rowGroup;
}
},
'stateLoadParams': function(settings, data)
{
var api = new $.fn.dataTable.Api(settings);
if (typeof api.rowGroup === "function" && "rowGroup" in data)
{
api.rowGroup().enable(data.rowGroup.enable);
if ("dataSrc" in data.rowGroup)
{
api.rowGroup().dataSrc(data.rowGroup.dataSrc);
//apply fixed order for group column
var fixedOrder = {
pre: [data.rowGroup.dataSrc, 'asc']
};
api.order.fixed(fixedOrder);
}
delete data.rowGroup;
}
}, },
'stateSaveCallback': function(settings, data) 'stateSaveCallback': function(settings, data)
{ {
@ -847,6 +886,28 @@ $(".change-table-columns-visibility-button").on("click", function(e)
var dataTable = $(dataTableSelector).DataTable(); var dataTable = $(dataTableSelector).DataTable();
var columnCheckBoxesHtml = ""; var columnCheckBoxesHtml = "";
var rowGroupRadioBoxesHtml = "";
var rowGroupDefined = typeof dataTable.rowGroup === "function";
if (rowGroupDefined)
{
var rowGroupChecked = (dataTable.rowGroup().enabled()) ? "" : "checked";
rowGroupRadioBoxesHtml = ' \
<div class="custom-control custom-radio custom-control-inline"> \
<input ' + rowGroupChecked + ' class="custom-control-input change-table-columns-rowgroup-toggle" \
type="radio" \
name="column-rowgroup" \
id="column-rowgroup-none" \
data-table-selector="' + dataTableSelector + '" \
data-column-index="-1" \
> \
<label class="custom-control-label" \
for="column-rowgroup-none">' + __t("None") + ' \
</label > \
</div>';
}
dataTable.columns().every(function() dataTable.columns().every(function()
{ {
var index = this.index(); var index = this.index();
@ -864,7 +925,7 @@ $(".change-table-columns-visibility-button").on("click", function(e)
checked = ""; checked = "";
} }
columnCheckBoxesHtml += '<div class="form-group"> \ columnCheckBoxesHtml += ' \
<div class="custom-control custom-checkbox"> \ <div class="custom-control custom-checkbox"> \
<input ' + checked + ' class="form-check-input custom-control-input change-table-columns-visibility-toggle" \ <input ' + checked + ' class="form-check-input custom-control-input change-table-columns-visibility-toggle" \
type="checkbox" \ type="checkbox" \
@ -875,12 +936,41 @@ $(".change-table-columns-visibility-button").on("click", function(e)
<label class="form-check-label custom-control-label" \ <label class="form-check-label custom-control-label" \
for="column-' + index.toString() + '">' + title + ' \ for="column-' + index.toString() + '">' + title + ' \
</label> \ </label> \
</div> \ </div>';
</div>'
if (rowGroupDefined)
{
var rowGroupChecked = "";
if (dataTable.rowGroup().enabled() && dataTable.rowGroup().dataSrc() == index)
{
rowGroupChecked = "checked";
}
rowGroupRadioBoxesHtml += ' \
<div class="custom-control custom-radio"> \
<input ' + rowGroupChecked + ' class="custom-control-input change-table-columns-rowgroup-toggle" \
type="radio" \
name="column-rowgroup" \
id="column-rowgroup-' + index.toString() + '" \
data-table-selector="' + dataTableSelector + '" \
data-column-index="' + index.toString() + '" \
> \
<label class="custom-control-label" \
for="column-rowgroup-' + index.toString() + '">' + title + ' \
</label > \
</div>';
}
}); });
var message = '<div class="text-center"><h4>' + __t('Hide/view columns') + '</h4><div class="text-left form-group">' + columnCheckBoxesHtml + '</div></div>';
if (rowGroupDefined)
{
message += '<hr><div class="text-center mt-1"><h4>' + __t('Group by') + '</h4><div class="text-left form-group">' + rowGroupRadioBoxesHtml + '</div></div>';
}
bootbox.dialog({ bootbox.dialog({
message: '<div class="text-center"><h5>' + __t('Hide/view columns') + '</h5><hr><div class="text-left">' + columnCheckBoxesHtml + '</div></div>', message: message,
size: 'small', size: 'small',
backdrop: true, backdrop: true,
closeButton: false, closeButton: false,
@ -896,6 +986,7 @@ $(".change-table-columns-visibility-button").on("click", function(e)
} }
}); });
}); });
$(document).on("click", ".change-table-columns-visibility-toggle", function() $(document).on("click", ".change-table-columns-visibility-toggle", function()
{ {
var dataTableSelector = $(this).attr("data-table-selector"); var dataTableSelector = $(this).attr("data-table-selector");
@ -904,3 +995,32 @@ $(document).on("click", ".change-table-columns-visibility-toggle", function()
dataTable.columns(columnIndex).visible(this.checked); dataTable.columns(columnIndex).visible(this.checked);
}); });
$(document).on("click", ".change-table-columns-rowgroup-toggle", function()
{
var dataTableSelector = $(this).attr("data-table-selector");
var columnIndex = $(this).attr("data-column-index");
var dataTable = $(dataTableSelector).DataTable();
if (columnIndex == -1)
{
dataTable.rowGroup().enable(false);
//remove fixed order
dataTable.order.fixed({});
}
else
{
dataTable.rowGroup().enable(true);
dataTable.rowGroup().dataSrc(columnIndex);
//apply fixed order for group column
var fixedOrder = {
pre: [columnIndex, 'asc']
};
dataTable.order.fixed(fixedOrder);
}
dataTable.draw();
});

View File

@ -580,7 +580,7 @@
<th>{{ $__t('Quantity unit from') }}</th> <th>{{ $__t('Quantity unit from') }}</th>
<th>{{ $__t('Quantity unit to') }}</th> <th>{{ $__t('Quantity unit to') }}</th>
<th>{{ $__t('Factor') }}</th> <th>{{ $__t('Factor') }}</th>
<th class="d-none">Hidden group</th> <th>{{ $__('Group')}}</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>

View File

@ -156,7 +156,7 @@
<th>{{ $__t('Product') }}</th> <th>{{ $__t('Product') }}</th>
<th>{{ $__t('Amount') }}</th> <th>{{ $__t('Amount') }}</th>
<th class="fit-content">{{ $__t('Note') }}</th> <th class="fit-content">{{ $__t('Note') }}</th>
<th class="d-none">Hidden ingredient group</th> <th>{{ $__t('Ingredient group') }}</th>
</tr> </tr>
</thead> </thead>
<tbody class="d-none"> <tbody class="d-none">

View File

@ -20,7 +20,6 @@
tr.dtrg-group { tr.dtrg-group {
cursor: pointer; cursor: pointer;
} }
</style> </style>
@endpush @endpush
@ -184,7 +183,7 @@
</th> </th>
<th>{{ $__t('Product') }} / <em>{{ $__t('Note') }}</em></th> <th>{{ $__t('Product') }} / <em>{{ $__t('Note') }}</em></th>
<th>{{ $__t('Amount') }}</th> <th>{{ $__t('Amount') }}</th>
<th class="d-none">Hidden product group</th> <th>{{ $__t('Product group') }}</th>
<th class="d-none">Hidden status</th> <th class="d-none">Hidden status</th>
@include('components.userfields_thead', array( @include('components.userfields_thead', array(
@ -251,7 +250,7 @@
@endif @endif
<span class="locale-number locale-number-quantity-amount">{{ $listItem->amount }}</span> @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural) }}@endif <span class="locale-number locale-number-quantity-amount">{{ $listItem->amount }}</span> @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural) }}@endif
</td> </td>
<td class="d-none"> <td>
@if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)->name }} @else <span class="font-italic font-weight-light">{{ $__t('Ungrouped') }}</span> @endif @if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)->name }} @else <span class="font-italic font-weight-light">{{ $__t('Ungrouped') }}</span> @endif
</td> </td>
<td id="shoppinglistitem-{{ $listItem->id }}-status-info" <td id="shoppinglistitem-{{ $listItem->id }}-status-info"

View File

@ -114,7 +114,7 @@
</th> </th>
<th>{{ $__t('Task') }}</th> <th>{{ $__t('Task') }}</th>
<th>{{ $__t('Due') }}</th> <th>{{ $__t('Due') }}</th>
<th class="d-none">Hidden category</th> <th>{{ $__t('Category') }}</th>
<th>{{ $__t('Assigned to') }}</th> <th>{{ $__t('Assigned to') }}</th>
<th class="d-none">Hidden status</th> <th class="d-none">Hidden status</th>
@ -176,7 +176,7 @@
<time class="timeago timeago-contextual" <time class="timeago timeago-contextual"
datetime="{{ $task->due_date }}"></time> datetime="{{ $task->due_date }}"></time>
</td> </td>
<td class="d-none"> <td>
@if($task->category_id != null) <span>{{ FindObjectInArrayByPropertyValue($taskCategories, 'id', $task->category_id)->name }}</span> @else <span class="font-italic font-weight-light">{{ $__t('Uncategorized') }}</span>@endif @if($task->category_id != null) <span>{{ FindObjectInArrayByPropertyValue($taskCategories, 'id', $task->category_id)->name }}</span> @else <span class="font-italic font-weight-light">{{ $__t('Uncategorized') }}</span>@endif
</td> </td>
<td> <td>