<div>
<ejs-dropdownlist id="games" dataSource="@ViewBag.data" select="select" popupWidth="300px" placeholder="Select a game" popupHeight="220px">
</ejs-dropdownlist>
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" allowPaging="true" toolbar="@(new List<string>() { "Search" })">
<e-grid-selectionSettings persistSelection="true" checkboxOnly="true"></e-grid-selectionSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" type="string" width="150"></e-grid-column>
<e-grid-column field="OrderDate" headerText=" Order Date" type="date" format="yMd" width="130"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" format="C2" type="number" width="120"></e-grid-column>
<e-grid-column field="ShippedDate" headerText="Shipped Date" type="date" format="yMd" width="140"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function select(args) {
var type = "";
if (args.itemData.value == "Date") {
type = "date";
} else if (args.itemData.value == "String") {
type = "string";
} else if (args.itemData.value == "Currency") {
type = "number";
}
var gridObj = document.getElementsByClassName('e-grid')[0]['ej2_instances'][0]
for (var i = 0; i < gridObj.getColumns().length; i++) {
if (gridObj.getColumns()[i].type == type) {
gridObj.hideColumns([gridObj.getColumns()[i].headerText]);
} else if (gridObj.getColumns()[i].type == type) {
gridObj.hideColumns([gridObj.getColumns()[i].headerText]);
}
else if (gridObj.getColumns()[i].type == type) {
gridObj.hideColumns([gridObj.getColumns()[i].headerText]);
}
}
}
</script> |