Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°6218 - 1:n & n:n - Read mode: No refresh of tab count on Add/Remove… #571

Open
wants to merge 1 commit into
base: support/3.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions js/dataTables.settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ $(function () {
this.element.block();

$.post(this.options.sRenderUrl, oParams, function(data) {

let oTableElement = $('#'+me.options.sListId);
let oDataTable = oTableElement.DataTable();

// Nasty workaround to clear the pager's state for paginated lists !!!
// See jquery.tablesorter.pager.js / saveParams / restoreParams
if (window.pager_params) {
window.pager_params['pager'+me.options.sListId] = undefined;
}
var parentElt = $('#'+me.options.sListId).closest('.dataTables_wrapper').parent();
var aOptions = $('#'+me.options.sListId).DataTable().context[0].oInit;
var parentElt = oTableElement.closest('.dataTables_wrapper').parent();
var aOptions = oDataTable.context[0].oInit;
window['bSelectAllowed'+me.options.sListId] = false;
$('#'+me.options.sListId).DataTable().destroy(true);
oDataTable.destroy(true);
var sThead = "";
if (me.options.sSelectMode != "") {
sThead += "<th></th>";
Expand Down Expand Up @@ -127,7 +131,20 @@ $(function () {
aOptions["lengthMenu"] = [[oParams.end, oParams.end * 2, oParams.end * 3, oParams.end * 4, -1], [oParams.end, oParams.end * 2, oParams.end * 3, oParams.end * 4, aOptions["lengthMenu"]]];
aOptions["ajax"] = eval(aOptions["ajax"]);

$('#'+me.options.sListId).DataTable(aOptions);
// Rebuild table
oTableElement = $('#'+me.options.sListId);
oDataTable = oTableElement.DataTable(aOptions);

// Update tab information (when data received)
oDataTable.on('xhr', ( e, settings, json, xhr) => {
const sPanelTitle = oParams['extra_params']['panel_title']; // retrieve panel title
const oTabsPanel = oTableElement.closest('.ui-tabs-panel'); // search for tabs panel
if(oTabsPanel !== undefined){
const sLabelledBy = oTabsPanel.attr('aria-labelledby'); // key to search for corresponding tab
const oTab = $(`.ibo-tab-container .ui-tabs-tab[aria-labelledby="${sLabelledBy}"] a`); // tab
oTab.html(json.recordsTotal > 0 ? sPanelTitle + ` (${json.recordsTotal})` : sPanelTitle); // update tab information
Comment on lines +143 to +145
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to js/layouts/tab-container/tab-container.js so it's re-useable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it could be useful

}
});

me.element.unblock();

Expand Down