<ejs-grid id="Grid" dataSource="@ViewBag.datasource" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" edit="@(new {create = "create", read = "read", destroy = "destroy", write = "write"})" type="string" width="120"></e-grid-column>
. . .
</e-grid-columns>
</ejs-grid>
<script>
var elem;
var drpObj;
function create(args) {
elem = document.createElement('input');
return elem;
}
function write(args) {
var grid = document.getElementById('Grid')["ej2_instances"][0];
var data = grid.dataSource;
drpObj = new ej.dropdowns.DropDownList({
value: args.rowData[args.column.field],
dataSource: data,
change: function (args) {
var ajax = new ej.base.Ajax("Home/db", "GET");
ajax.type = 'POST'
ajax.data = JSON.stringify(args.value);
ajax.send();
ajax.onSuccess = function (data) {
data = JSON.parse(data);
grid.element.querySelector('.e-gridform input#GridFreight').value = data[0]['Freight'];
grid.element.querySelector('.e-gridform input#GridShipCity').value = data[0]['ShipCity'];
grid.element.querySelector('.e-gridform input#GridEmployeeID').value = data[0]['EmployeeID'];
};
},
fields: { text: 'CustomerID', value: 'CustomerID' },
});
drpObj.appendTo(elem);
}
function destroy() {
drpObj.destroy();
}
function read(args) {
return drpObj.value;
}
</script>
|
|
|
...
<script>
...
function write(args) {
var grid = document.getElementById('Grid')["ej2_instances"][0];
var data = grid.dataSource;
drpObj = new ej.dropdowns.DropDownList({
value: args.rowData[args.column.field],
dataSource: data,
change: function (args) {
var obj = {"NumCertificado": args.value, "FormatoID": 21}
var ajax = new ej.base.Ajax("Home/db", "GET");
ajax.type = 'POST'
ajax.data = JSON.stringify(obj);
ajax.send();
ajax.onSuccess = function (data) {
data = JSON.parse(data);
...
};
},
}); drpObj.appendTo(elem);
}
...
</script> |
public object DB([FromBodyAttribute] valus val)
{
var value = val.NumCertificado;
var Data = Orders.GetAllRecords();
Data = Data.Where(ord => ord.CustomerID == value).ToList();
return Data;
}
public class valus {
public int FormatoID { get; set; }
public string NumCertificado { get; set; }
} |