How to change the PivotGrid layout in PivotClient dynamically?
This KB showcases the example to change the PivotGrid layout in PivotClient dynamically (OLAP server).
Solution:
You can change the grid layout types dynamically in the OLAP server mode and view the desired summaries in the PivotGrid control inside the PivotClient control through the following steps:
Step 1:
Add a button to the PivotClient Toolbar to change the grid layout type dynamically. To create a button inside the Toolbar, you can use the renderSuccess event of the PivotClient. Refer to the following codes for this customization.
JavaScript
$("#PivotClient1").ejPivotClient({
//dataSource
renderSuccess: ”pivotClientSuccess”
});
ASP
<ej:PivotClient ID="PivotClient1" runat="server" Title="Relational Browser" ClientIDMode="Static"> <ClientSideEvents RenderSuccess="pivotClientSuccess" /> </ej:PivotClient>
RAZOR
@Html.EJ().Pivot().PivotClient("PivotClient1").ClientSideEvents(oEve => { oEve.RenderSuccess("pivotClientSuccess ")})
JavaScript
function pivotClientSuccess(args) {
var btn = '<div style="margin-top:2px;"><button class="cusBtn" id="Btn1" style="background-color:white;">Layouts</button></div>';
$(".e-reportToolbar").append(btn);
$("#Btn1").ejButton({ roundedCorner: true, size: "mini", type: ej.ButtonType.Button, click: "OpenLayoutDialog" });
}
Step 2:
Design the layout-type dialog on the click event of the customized button (Layouts) using the following code.
JavaScript
function OpenLayoutDialog(args) {
var pivotClient = $('.e-pivotclient').data("ejPivotClient");
$(".e-dialog").remove();
var ejDialog = "<div id='layoutDialog'></div>";
var dialogContent = ej.buildTag("div#layoutTable", "<table><tr><td><label id=''>Layout Types:</label></td><td><input id='drpdwn1'></input></td></tr></table>")[0].outerHTML;
var OKBtn = ej.buildTag("button#OKBtn.e-dialogOKBtn", "", {}, { name: "OK" })[0].outerHTML;
var CancelBtn = ej.buildTag("button#CancelBtn.e-dialogCancelBtn", "", {}, { name: "Cancel" })[0].outerHTML;
var dialogFooter = ej.buildTag("div", OKBtn + CancelBtn, { "float": "right", "margin": "20px 0px 6px" })[0].outerHTML;
$(".e-pivotclient").after(ejDialog);
$("#layoutDialog").append(dialogContent + dialogFooter);
$("#layoutDialog").ejDialog({ width: "auto", target: "#" + pivotClient._id, enableResize: false, close: ej.proxy(ej.Pivot.closePreventPanel, this) });
$(".e-titlebar").prepend(ej.buildTag("div", "Layout Types", { "display": "inline" })[0].outerHTML)[0];
$("#OKBtn").ejButton({
roundedCorner: true, size: "small", type: ej.ButtonType.Button, text: "OK",
click: "Apply"
});
$("#CancelBtn").ejButton({
roundedCorner: true,
size: "small",
type: ej.ButtonType.Button,
text: "Cancel",
click: function (args) {
this.element.parents(".e-dialog").remove();
}
});
$("#drpdwn1").ejDropDownList({
dataSource: [{ option: "Normal", value: "normal" },
{ option: "NormalTopSummary ", value: "normaltopsummary" },
{ option: "No Summaries", value: "nosummaries" },
{ option: "ExcelLike Layout", value: "excellikelayout" },
],
fields: { text: "option", value: "value" },
selectedIndices: [0],
height: "30px",
});
}

Summary Types 1
Step 3:
After selecting the layout type through the layout-type dialog, it will be reflected in the PivotGrid control. Refer to the following code snippet to apply the desired summaries in the PivotGrid control.
JavaScript
function Apply(args) {
var pivotClient = $('.e-pivotclient').data("ejPivotClient");
pivotClient._waitingPopup.show();
if (this.element.parents(".e-pivotclient").length > 0)
pivotClient.model.gridLayout = $("#drpdwn1").data("ejDropDownList").model.value;
if (pivotClient._pivotGrid) {
pivotClient._pivotGrid.model.gridLayout = pivotClient.model.gridLayout;
pivotClient._pivotGrid.doAjaxPost("POST", pivotClient._pivotGrid.model.url + "/" + pivotClient._pivotGrid.model.serviceMethodSettings.initialize, JSON.stringify({ "action": "initializeGrid", "currentReport": pivotClient._pivotGrid.model.currentReport, "customObject": "", "gridLayout": pivotClient._pivotGrid.model.gridLayout }), pivotClient._pivotGrid._renderControlSuccess);
}
$(".e-dialog").remove();
}
Conclusion
I hope you enjoyed learning about how to change the PivotGrid layout in PivotClient dynamically.
You can refer to our JavaScript PivotClient feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript PivotClient example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!