|
[index.cshtml]
@{
var ChildGrid = new Syncfusion.EJ2.Grids.Grid()
{
DataSource = (IEnumerable<object>)ViewBag.DataSource,
QueryString = "EmployeeID",
EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings() { Mode = Syncfusion.EJ2.Grids.EditMode.Dialog, AllowAdding = true, AllowEditing = true, AllowDeleting = true },
Columns = new List<Syncfusion.EJ2.Grids.GridColumn> {
new Syncfusion.EJ2.Grids.GridColumn(){ Field="OrderID", HeaderText="Order ID", Width="120" },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="Freight", HeaderText="Freight", Width="120", Format="C2", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Right, Edit=new { create = "create", read = "read", destroy = "destroy", write = "write" }},
new Syncfusion.EJ2.Grids.GridColumn(){ Field="CustomerID", HeaderText="Customer ID", Width="150" },
},
};
}
<div class="control-section">
<ejs-grid id="HierarchyPrint" dataSource="ViewBag.DataSource2" childGrid="ChildGrid" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="UnitID" headerText="Unit ID" isPrimaryKey="true" textAlign="Right" width="125"></e-grid-column>
<e-grid-column field="MinPoint" headerText="MinPoint" textAlign="Right" width="125"></e-grid-column>
<e-grid-column field="MaxPoint" headerText="MaxPoint" width="135"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
var elem;
var dObj;
let sportsData = [
{ Freight: 1 },
{ Freight: 2 },
{ Freight: 3 },
{ Freight: 4 },
{ Freight: 5 },
{ Freight: 6 },
{ Freight: 7 },
{ Freight: 8 },
{ Freight: 9 },
{ Freight: 10 },
{ Freight: 11 },
{ Freight: 12 },
{ Freight: 13 },
{ Freight: 15 },
{ Freight: 16 },
{ Freight: 17 }
];
function create(args) {
elem = document.createElement('input');
return elem;
}
function write(args) {
// get the parent row element
var parentrow = document.querySelector("#" + args.element.id.split(args.column.field)[0]).closest('tr').previousElementSibling;
// get the parent Grid instances
var parentGrid = document.getElementById('HierarchyPrint').ej2_instances[0];
// get the parent row data
parentRowData = parentGrid.getRowObjectFromUID(parentrow.getAttribute('data-uid'));
// generate the predicates based on the MinPoint and MaxPoint
var predicate = new ej.data.Predicate('Freight', 'greaterthan', parentRowData.data.MinPoint);
predicate = predicate.and('Freight', 'lessthan', parentRowData.data.MaxPoint);
dObj = new ej.dropdowns.DropDownList({
//set the data to dataSource property
dataSource: sportsData,
query: new ej.data.Query().where(predicate), // apply the filter query
// maps the appropriate column to fields property
fields: { value: 'Freight' },
});
dObj.appendTo(elem);
}
function destroy() {
dObj.destroy();
}
function read(args) {
return dObj.value;
}
</script> |
|
function write(args) {
------
dObj = new ej.dropdowns.DropDownList({
//set the data to dataSource property
dataSource: sportsData,
placeholder: args.column.field,
floatLabelType: "Always",
query: new ej.data.Query().where(predicate),
// maps the appropriate column to fields property
fields: { value: 'Freight' },
});
dObj.appendTo(elem);
}
|