Hi Alberto,
We have achieved the requirement using the toolbarClick event. You can also perform Edit, Add operations in an individual screen. Please refer to the below code example to achieve Add, Edit and Delete operations. toolbarClick: function (args) { switch (args.itemName) { case "Add": //Adding the record args.cancel = true; myapp.showScreen("AddEditTable1Item", null, { beforeShown: function (addScreen) { var ord = new myapp.Table1Item(); addScreen.Table1Item = ord; } }); break; case "Edit": //Editing the record if (!($.isEmptyObject(selectedData))) { args.cancel = true; myapp.showScreen("AddEditTable1Item", [selectedData]) } break; } toolbarClick: function (args) { switch (args.itemName) { case "Excel Export": // Grid exporting this.model["exportdata"] =this.model.dataSource.map(function (obj) { return { OrderID: obj.OrderID, EmployeeID: obj.EmployeeID, City: obj.City, Freight: obj.Freight }; }); this.export('../api/Values/ExcelExport') e.cancel = true; } // Cilent side toolbarClick: function (args) { switch (args.itemName) { case "Excel Export": // Grid exporting this.model["exportdata"] = this.getSelectedRecords() } } public void ExportToExcel(string GridModel) { ExcelExport exp = new ExcelExport();// Pass selected records alone for exporting exp.Export(obj, this.ExportData, "Export.xlsx", ExcelVersion.Excel2010,false, false, "flat-saffron"); private GridProperties ConvertGridObject(string gridProperty) { JavaScriptSerializer serializer = new JavaScriptSerializer(); IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty,typeof(IEnumerable)); GridProperties gridProp = new GridProperties(); foreach (KeyValuePair<string, object> ds in div) { if (ds.Key == "selectedRecords") {();// Serialize the selected records string serialize = serializer.Serialize(ds.Value); this.ExportData = (List<OrdersView>)serializer.Deserialize(serialize,typeof(List<OrdersView>)); continue; } var property = gridProp.GetType().GetProperty(ds.Key,BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); if (property != null) { Type type = property.PropertyType; string serialize = serializer.Serialize(ds.Value); object value = serializer.Deserialize(serialize, type); property.SetValue(gridProp, value, null); } } return gridProp; http://www.syncfusion.com/downloads/support/forum/120570/ze/Grid-Exporting379737180
Query #1: My question is how to allow the grid data to be physically saved to the database. I need to perform, add, delete and edit functions. This is my code:
In the previous version, we passed Grid dataSource using the dataManager which made some issue with saving dataSource. But in the latest version issues have been fixed and you can save the dataSource.
Query #2: Would it be better to create add/view independent screens to allow the above instead of using the grid for such operations?
}
Query #3: The exporting functions need a webapi, the one I am using is a standard one based on code I have seen in your examples. Apparently I need to create webapi’ s for each table in my database, is there a way to create just one single webapi that can use the entity name to do it's exporting operations (for both the grid data as well as individual record selected)? And if so could you provide me with an example?
This requirement is achieved using export method in Grid. You can use single webapi for multigrid exporting.
}
For individual selected record exporting, we have passed the selected records to the export function.
}
}
We have created a sample and attached for your reference,
Regards,
Isuriya R
case "Edit":
if (($.isEmptyObject(selectedData)) || (selectedData === undefined)) {
msls.showMessageBox("Display message")
}
But, did not get anywhere, the same error occurs.
var selectedData = null; case "Edit": if (selectedData!= null && !($.isPlainObject(selectedData))) { args.cancel = true; myapp.showScreen("AddEditTable1Item", [selectedData]) } |
//push the selectedRecords in ignoreonexport toolbarClick: function (args) { . . .
case "Excel Export": args.cancel = true; if (this.selectedRowsIndexes.length > 0) //export selected records this.model["exportdata"] = this.getSelectedRecords().map(function (obj) { // get selected records by using this.getSelectedRecords() return { OrderID: obj.OrderID, EmployeeID: obj.EmployeeID, City: obj.City, Freight: obj.Freight }; }); else this.model["exportdata"] = this.model.dataSource.map(function (obj) { //export entire datasource return { OrderID: obj.OrderID, EmployeeID: obj.EmployeeID, City: obj.City, Freight: obj.Freight }; });
this.export('../api/Values/ExcelExport') } } |
[System.Web.Http.ActionName("ExcelExport")] [AcceptVerbs("POST")] public void ExcelExport() { string gridModel = HttpContext.Current.Request.Params["GridModel"]; GridProperties gridProperty = ConvertGridObject(gridModel); ExcelExport exp = new ExcelExport();
using (ServerApplicationContext context = ServerApplicationContext.CreateContext()) { exp.Export(gridProperty, (IEnumerable)gridProperty.DataSource, "Export.xlsx", ExcelVersion.Excel2010); } } private GridProperties ConvertGridObject(string gridProperty) { JavaScriptSerializer serializer = new JavaScriptSerializer(); IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable)); IEnumerable<Order> data = null; GridProperties gridProp = new GridProperties(); foreach (KeyValuePair<string, object> ds in div) { var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); if (property != null) { Type type = property.PropertyType; string serialize = serializer.Serialize(ds.Value); object value = serializer.Deserialize(serialize, type); property.SetValue(gridProp, value, null); } if (ds.Key == "exportdata" ) { string serialize = serializer.Serialize(ds.Value); data = serializer.Deserialize<Order[]>(serialize).Cast<Order>().ToList(); } } gridProp.DataSource = data; return gridProp; |
Please check and get back to us for further assistance.
Regards,
Isuriya R