[index.cshtml]
<div class="control-section">
<button id="showBtn" onclick="onShowColumns()">Show Columns</button>
<button id="hideBtn" onclick="onHideColumns()">Hide Columns</button>
<ejs-grid id="Grid" dataSource="ViewBag.PurchaseData" allowPaging="true" allowResizing="true" allowReordering="true" gridLines="Both">
<e-grid-columns>
<e-grid-column field="TotalPrice" headerText="Total Price" textAlign="Right" format="C2" width="120"></e-grid-column>
<e-grid-column field="Price" headerText="Price" format="C2" width="150"></e-grid-column>
<e-grid-column field="Tax" headerText="Tax" textAlign="Right" format="C2" width="120"></e-grid-column>
<e-grid-column field="Shipping" headerText="Shipping" width="200"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function onShowColumns(e) {
var grid = document.getElementById("Grid").ej2_instances[0];
grid.showColumns(["Price", "Tax", "Shipping"]);
}
function onHideColumns(e) {
var grid = document.getElementById("Grid").ej2_instances[0];
grid.hideColumns(["Price", "Tax", "Shipping"]);
}
</script> |
[index.cshtml]
<ejs-grid id="Grid" dataSource="ViewBag.PurchaseData" allowPaging="true" allowResizing="true" allowReordering="true" gridLines="Both">
<e-grid-columns>
<e-grid-column field="TotalPrice" headerText="Total Price" textAlign="Right" format="C2" allowReordering="false" width="120"></e-grid-column>
<e-grid-column field="Price" headerText="Price" format="C2" allowReordering="false" width="150"></e-grid-column>
<e-grid-column field="Tax" headerText="Tax" textAlign="Right" format="C2" allowReordering="false" width="120"></e-grid-column>
<e-grid-column field="Shipping" headerText="Shipping" width="200" allowReordering="false"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="200"></e-grid-column>
<e-grid-column field="CustomerAddress" headerText="Customer Address" width="200"></e-grid-column>
<e-grid-column field="Paymode" headerText="Pay Mode" width="200"></e-grid-column>
</e-grid-columns>
</ejs-grid>
|