<div id="Grid"></div>
<script> $(function () { $("#Grid").ejGrid({ dataSource: ej.DataManager({ url: "/Home/DataSource", insertUrl: "/Home/Insert", updateUrl: "/Home/Update", removeUrl: "/Home/Delete", adaptor: new ej.UrlAdaptor() }), allowPaging: true, . . . . . columns: [ { field: "OrderID", isPrimaryKey: true, isIdentity: true, width: 90 }, . . . . .
] });
}); </script>
public ActionResult Insert(EditableOrder value) {
value.OrderID = OrderRepository.GetAllRecords().Last().OrderID + 1; OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); |
<script type="text/javascript"> $(function () { $("#Grid").ejGrid({
editSettings: { allowAdding: true, allowDeleting: true, allowEditing: true }, toolbarSettings: { showToolbar: true, toolbarItems: ["add", "edit", "delete", "cancel"] }, columns: [
{ field: "OrderID", headerText: "Order ID", isPrimaryKey: true, defaultValue: 12345, width: 90 }, ] }); }); |
If we misunderstood your requirement please provide below details,
1. Grid rendering code example.
2. Screenshot of the exact requirement.
3. Detailed explanation of your requirement.
The provided information will help to analyze the requirement and provide you the response as early as possible.
Regards,
Gowthami V.
<div id="Grid"></div>
<script type="text/javascript"> $(function () { var element = $("#Grid"); element.ejGrid({ dataSource: window.gridData, allowPaging: true, actionBegin: "beginEvent", . . . .. columns: [ { field: "OrderID", isPrimaryKey: true }, { field: "OrderDate", editType: ej.Grid.EditingType.DateTimePicker, format: "{0:MM/dd/yyyy hh:mm}" }, . . . .
]
}); }); function beginEvent(args) { if ((args.requestType == "add")) { args.data.OrderDate = ej.globalize.format(new Date, "MM/dd/yyyy"); } } |
1) You would like to update the sequential number, while adding a new row or saving a record?
Refer the following Help Document for actionBegin event.
http://help.syncfusion.com/js/api/ejgrid#events:actionbegin
Regards,
Seeni Sakthi Kumar S.
<div id="Grid"></div> <script type="text/javascript"> $(function () { $("#Grid").ejGrid({ // the datasource "window.gridData" is referred from jsondata.min.js dataSource: window.gridData, . . . . columns: [ { field: "OrderID", isPrimaryKey: true }, . . . .. { field: "ShipCity", headerText: 'Ship City', editType: ej.Grid.EditingType.Dropdown } ], actionBegin: function (args) { if ((args.requestType == 'add')) { args.data.CustomerID = 'stefano' args.data.ShipCity = 'Lyon'; args.data.Verified = true; } }, actionComplete: function (args) { if ((args.requestType == 'add')) { this.element.find(".gridform #GridShipCity").ejDropDownList("setSelectedValue", args.data.ShipCity)//GridShipCity==>Id of Grid + FieldName } }, }); }); |
<div id="Grid"></div> <script type="text/javascript"> $(function () { $("#Grid").ejGrid({ // the datasource "window.gridData" is referred from jsondata.min.js dataSource: window.gridData, allowPaging: true, editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, columns: [ { field: "OrderID", isPrimaryKey: true }, . . . . . { field: "EmployeeID", foreignKeyField: 'EmployeeID', foreignKeyValue: 'FirstName', dataSource: window.employeeView, editParams: { fields: {//editParams must be defined like this text: "EmployeeID", text: "FirstName" }, dataSource: window.employeeView } } ] }); }); |
<div id="Grid"></div> <script type="text/javascript"> $(function () {
var dpDataSource = [ { value: 0, text: 'Zero' }, { value: 1, text: 'One' }, { value: 2, text: 'Two' }, { value: 3, text: 'Three' }, { value: 4, text: 'Four' }, { value: 5, text: 'Five' }, { value: 6, text: 'Six' }, { value: 7, text: 'Seven' }, { value: 8, text: 'Eight' }, { value: 9, text: 'Nine' }, { value: 10, text: 'Ten' }, ] $("#Grid").ejGrid({ // the datasource "window.gridData" is referred from jsondata.min.js dataSource: window.gridData, allowPaging: true, editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, columns: [ { field: "OrderID", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true }, width: 85 }, . . . { field: "EmployeeID", editType: ej.Grid.EditingType.Dropdown, dataSource: dpDataSource } ] } }); }); |
<div id="Grid"></div> <script type="text/javascript"> $(function () { . . . . $("#Grid").ejGrid({ dataSource: gridData, allowPaging: true, columns: [ { field: "OrderId", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true }, width: 85 }, { field: "Drop", headerText: 'Drop', width: 100, type: 'number', dataSource: dpDataSource, foreignKeyField: 'value', foreignKeyValue: 'text', editType: ej.Grid.EditingType.Dropdown, editParams: { dataSource: dpDataSource } }, ], actionBegin: function (args) { if ((args.requestType == 'add')) { args.data.OrderId = 99; args.data.Drop = 3; } }, actionComplete: function (args) { if ((args.requestType == 'add')) { this.element.find(".gridform #GridDrop").ejDropDownList("setSelectedValue", args.data.Drop)// GridDrop ==>Id of Grid + FieldName } },
}); }); |