sapui5tutors SAPUI5 • Fiori • SAP BTP Step-by-step tutorials Real project examples Interview Q&A
Practical SAPUI5 • Fiori • SAP BTP tutorials and interview prep

SAPUI5 Table Personalization: Sort, Filter, Group

Users expect to rearrange table columns, hide the ones they do not need, and have the app remember. Building that by hand means a settings dialog, persistence, and restore logic — all boilerplate. The TablePersoController ships all of it in one reusable component.

What TablePersoController Gives You

sap.m.TablePersoController attaches to any sap.m.Table and adds a personalization dialog: reorder columns, show/hide them, and persist the layout. You get the dialog, the persistence, and the restore behavior without writing any of it.

The minimal setup needs two things: the controller instance and a persistence provider. The provider decides where the settings are stored.

onInit: function () {
  this._oTPC = new TablePersoController({
    table: this.byId("ordersTable"),
    persoService: new TablePersoService() // your storage adapter
  }).activate();
}

Key takeaway: the controller is the behavior, the perso service is the storage. Implement storage once, reuse it across every table in the app.


The Personalization Service

The service is a small object with two methods — getPersData returns a promise of the stored settings, setPersData saves them. Storage is entirely your choice:

getPersData: function () {
  const sData = localStorage.getItem("perso-orders");
  return Promise.resolve(sData ? JSON.parse(sData) : null);
},
setPersData: function (oData) {
  localStorage.setItem("perso-orders", JSON.stringify(oData));
  return Promise.resolve();
}

localStorage is fine for demos. In production, persist per user — via the Fiori launchpad personalization service, a backend endpoint, or the unified shell container. The controller does not care where the JSON goes.


Opening the Dialog and Resetting

Wire a toolbar button to open the dialog, and offer a reset for users who want the default layout back:

onPersoPress: function () {
  this._oTPC.openDialog();
},
onPersoReset: function () {
  this._oTPC.getPersoService().setPersData(null);
  this._oTPC.refresh();
}

The dialog lists every column with a checkbox and up/down controls. Changes apply live and save automatically when the dialog closes. The table restores the saved layout on the next visit — including column widths, if you enable them.


Sort, Filter, and Group on Top

Column personalization covers layout; sorting, filtering, and grouping come from the view settings dialog (sap.m.ViewSettingsDialog) or the newer p13n APIs. The two complement each other:

  • ViewSettingsDialog — one dialog for sort, filter, and group-by, with confirm/cancel semantics. Apply the selections to the table binding with sorter and filters.
  • TablePersoController — column visibility and order, persisted per user.
  • Combined — store both the view settings and the column layout in the same perso payload so a "reset" restores everything at once.
onViewSettingsConfirm: function (oEvent) {
  const oBinding = this.byId("ordersTable").getBinding("items");
  oBinding.sort(oEvent.getParameter("sorters"));
  oBinding.filter(oEvent.getParameter("filters"));
}

Key takeaway: personalization is two halves — column layout (TablePersoController) and data shaping (sort/filter/group). Plan both before you start.


Things to Watch

Personalization restores column order by column ID, so give every column a stable id — auto-generated IDs change between renders and silently break restore. Also decide up front whether personalization applies per user or per role: a shared "admin" layout stored globally surprises users who rearranged things yesterday.

Say you have an order list with twelve columns where half the users only care about dates and statuses: TablePersoController gives them their compact table, the view settings dialog gives them their default sort, and your code stays at about twenty lines of glue.

Do you persist personalization per user, or have you found a better approach? Drop it in the comments.