- Home
- Forum
- ASP.NET MVC (Classic)
- Grid with Datatable
Grid with Datatable
.Datasource((System.Data.DataTable)ViewData["data"])
//.ActionMode(Syncfusion.Mvc.Grid.ActionMode.JSON)
.Caption("test")
.EnablePaging()
.EnableSorting()
.AutoFormat(Skins.Marble)
.AllowSearching(true)
.Editing(edit =>
{
edit.AllowEdit(true);
edit.EditMode(GridEditMode.Normal);
edit.TimeSpan(3000);
edit.PrimaryKey(new string[] { "Id" });
})
.ToolBar(tools =>
{
tools.Add(GridToolBarItems.Search)
.Add(GridToolBarItems.Edit)
.Add(GridToolBarItems.Update)
.Add(GridToolBarItems.Cancel)
;
})
.Column(cols =>
{
cols.Add("Id",false).AllowEditing(false);
cols.Add("French", false).AllowEditing(false);
cols.Add("English", false).AllowEditing(false);
})
)
{
var data = GetDataTableLocalization();
return View();
}
public ActionResult Index(PagingParams args)
{
IEnumerable data = GetDataTableLocalization().AsEnumerable();
return data.GridJSONActions<DataRow>();
}
{
//Customer customer = new Customer();
table.Columns.Add("French", typeof(string));
table.Columns.Add("English", typeof(string));
table.PrimaryKey = key;
table.Rows.Add("notifNouveauMessage", "Vous avez un nouveau message", "You have a new message");
table.Rows.Add("txtIdentifiant", "Identifiant", "login");
table.Rows.Add("btnAnnulation", "Annuler", "Cancel");
table.Rows.Add("btnValidation", "Valider", "Save");
table.Rows.Add("btnModification", "Modifier", "Update");
}
Hi Jaouen Cécile,
Thanks for using Syncfusion Products.
We regret for the inconvenience caused. We are unable to reproduce your reported issue in our end. We have created a simple sample to demonstrate this and the same can be downloaded from the below link.
sample: JsonDataTable.zip
Could you please replicate your issue in the above sample and send back to us so that we could able to sort out the cause of this issue and provide you a better solutions quickly?.
Please try the above sample and let us know if you have any concerns.
Regards,
Bala Murugan A.S
I am not having the same issue as Jaouen, but I am having difficulty with getting the Save action working when the Grid is bound to DataTable.
If I have a Grid bound to an Entity object, there is no problem, I run into all sorts of issues however when trying to edit a Grid bound to a data table, my SaveAction is always getting null result.
Is this the correct format?
public ActionResult JSONSave([Bind(Prefix = "updatedRecords")]DataTable orders)
I have also tried with IEnumerable<DataRow> and System.Data.DataRow without any luck
Can we please get an example where edit rows is working when bound to a System.Data.DataTable using ActionMode.JSON?
Hi Laszlo,
Thanks for using Syncfusion products.
We are glad to inform you that your requirement ("I am
having difficulty with getting the Save action working when the Grid is bound
to DataTable.") can be achieved by creating separate class for getting
current record values and we suggest you to use the SetField method to update
the current record values to the DataTable. Please refer the below code
snippets.
CODE SNIPPET:
[CSHTML]
@(Html.Syncfusion().Grid<System.Data.DataRow>("OrdersGrid")
//. . .
.Editing(edit =>
{
edit.AllowEdit(true);
edit.EditMode(GridEditMode.Normal);
edit.PrimaryKey(new string[]{"OrderID"});
})
.Mappers(map =>
{
map.SaveAction("OrderSave");
})
)
[CS]
public ActionResult OrderSave(OrderClass order)
{
var dataTabl = GetTable();
dataTabl.Rows.Find(order.OrderID).SetField("CustomerID",
order.CustomerID);
dataTabl.Rows.Find(order.OrderID).SetField("OrderDate",
order.OrderDate);
dataTabl.Rows.Find(order.OrderID).SetField("ShipCity",
order.ShipCity);
dataTabl.Rows.Find(order.OrderID).SetField("ShipPostalCode",
order.ShipPostalCode);
dataTabl.AcceptChanges();
return
dataTabl.AsEnumerable().GridJSONActions<System.Data.DataRow>();
}
public DataTable GetTable()
{
var connection = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString;
using (var dataAdapter = new SqlDataAdapter("SELECT *
from Orders", connection))
{
var dataTable = new DataTable();
dataAdapter.Fill(dataTable);
DataColumn[] key = new DataColumn[1];
key[0] = dataTable.Columns["OrderID"];
dataTable.PrimaryKey = key;
return dataTable;
}
}
For your convenience, we have prepared a simple sample to
demonstrate this and the same can be downloaded from the below link,
Link: SampleProject.zip
Please let us know if you need any further assistance.
Regards,
Silambarasan I
- 3 Replies
- 4 Participants
-
JC Jaouen Cécile
- Mar 15, 2013 02:17 PM UTC
- May 21, 2014 04:25 AM UTC