- Home
- Forum
- ASP.NET MVC
- Problem with cell number format after inline editing
Problem with cell number format after inline editing
Hi,
I've got a problem with parsing of a decimal number after inline editing.
I have defined a grid like this:
<div class="Row">
<div class="Column">
<div>
@(Html.EJ().Grid<SlimHub.Models.QuoteSimulationPlantCost>("QuoteSimulationPlantCostsGrid")
.Datasource(ds => ds.Json((IEnumerable<QuoteSimulationPlantCost>)Model.QuoteSimulationPlantCosts.ToList()).UpdateURL("../PlantCostEqUpdate").InsertURL("../PlantCostEqInsert").RemoveURL("../PlantCostEqDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit =>
{
edit.AllowAdding().AllowDeleting().AllowEditing();
})
.Locale("it-IT")
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.AllowResizing()
.AllowTextWrap(true)
.Columns(col =>
{
col.Field("PlantCostId").HeaderText("ID").HeaderTextAlign(TextAlign.Center).IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(40).Visible(false).Add();
col.Field("QuoteSimId").HeaderText("ID Simulazione").HeaderTextAlign(TextAlign.Center).DefaultValue(Model.QuoteSimId).Width(100).Visible(false).Add();
col.Field("EquipmentId").HeaderText("Product").ForeignKeyField("EquipmentId").ForeignKeyValue("EquipmentDesc").DataSource((IEnumerable<object>)ViewBag.Equipments).HeaderTextAlign(TextAlign.Center).Width(45).Add();
col.Field("Quantity").HeaderText("Quantità").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:n1}").Width(80).Add();
col.Field("UnitPrice").HeaderText("Prezzo Unitario").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:c2}").Width(80).Add();
col.Field("TotalPrice").HeaderText("Prezzo Totale").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:c2}").AllowEditing(false).Width(80).Add();
col.Field("Annotations").HeaderText("Note").HeaderTextAlign(TextAlign.Center).Format("{0:c2}").Width(80).Add();
})
.ClientSideEvents(eve =>
{
//eve.ActionComplete("complete").ActionBegin("begin").EndEdit("endEdit").EndAdd("endAdd");
eve.EndEdit("plantEndEdit");
})
)
</div>
</div>
</div>
When I try to change the value of a numeric cell (either Quantity value or UnitPrice value) the following controller method is called:
public ActionResult PlantCostEqUpdate(QuoteSimulationPlantCost value)
{
db.Entry(value).State = EntityState.Modified;
db.SaveChanges();
//db.Settings.Update(value);
var data = db.QuoteSimulations.ToList();
return Json(value, JsonRequestBehavior.AllowGet);
}
If the value typed in the grid cell is, for example, 10,0, in the object passed as parameter of the method I see 100, thai is the number without comma separator for decimal digits.
How can I set the value of the TotalPrice column to be the value of UnitPrice multiplied by Quantity?
Thanks.
Claudio
SIGN IN To post a reply.
10 Replies
JK
Jayaprakash Kamaraj
Syncfusion Team
September 2, 2016 12:01 PM UTC
Hi Claudio,
Thank you for contacting Syncfusion support.
Query 1: If the value typed in the grid cell is, for example, 10,0, in the object passed as parameter of the method I see 100, thai is the number without comma separator for decimal digits.
We have created sample based on your requirement but we are unable reproduce the issue at our end. Please refer to the below video.
Please share the following information to find the cause of the issue.
1. Share the video to show the issue.
2. Issue replication procedure.
3. Essential studio and browser version details.
4. System settings corresponding to Number format.
5. An issue reproducing sample if possible or replicate the issue in the following sample
Sample: http://www.syncfusion.com/downloads/support/forum/125673/ze/SyncfusionMvcApplication291074143758
Query 2: How can I set the value of the TotalPrice column to be the value of UnitPrice multiplied by Quantity?
We have achieved your requirement using queryCellInfo event. This event is triggered, every time when a request is made to access a particular cell information, element, and data. In this event, we can set text for cells only for display purpose. Please refer to the Help document, code example and sample.
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).InsertURL("/Grid/PerformInsert")
.UpdateURL("/Grid/PerformUpdate")
.RemoveURL("/Grid/PerformDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
…
}).ClientSideEvents(eve=>eve.QueryCellInfo("querycellinfo")))
<script type="text/javascript">
function querycellinfo(args) {
if (args.column.field == "TotalPrice") {
$(args.cell).text(args.data.EmployeeID * args.data.Freight);//For display purpose
}
}
</script> |
Sample: http://www.syncfusion.com/downloads/support/forum/125673/ze/SyncfusionMvcApplication291074143758
Regards,
Jayaprakash K.
CR
CLAUDIO RICCARDI
September 5, 2016 09:14 AM UTC
Hi,
thank you for your answer.
I have solved point 2 but I still have problems with point 1.
When I load the Edit page I see the following error message:
<<ej.culture.it-IT.min.js:1 Uncaught TypeError: ej.addCulture is not a function>>
This is the include scripts order I have in the _Layout.cshtml file:
<link rel='nofollow' href="@Url.Content("~/Content/font-awesome/css/font-awesome.min.css")" rel="stylesheet" />
<link rel='nofollow' href="@Url.Content("~/Content/ej/web/Default-theme/ej.widgets.all.min.css")" rel="stylesheet"/>
<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/jsrender.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.easing.1.3.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.globalize.min.js")"></script>
<script src="@Url.Content("~/Scripts/ej/ej.web.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/ej/ej.unobtrusive.min.js")"></script>
<script src="@Url.Content("~/Scripts/ej/ej.culture.it-IT.min.js")"></script>
I can't understand what is the cause uf this error...
PK
Prasanna Kumar Viswanathan
Syncfusion Team
September 5, 2016 10:51 AM UTC
Hi Claudio,
Query 1: “How can I set the value of the TotalPrice column to be the value of UnitPrice multiplied by Quantity?”
We are happy to hear that your issue has been resolved.
Query 2: “<<ej.culture.it-IT.min.js:1 Uncaught TypeError: ej.addCulture is not a function>>”
We checked with our sample by defining the script files with the mentioned order and we did not face any script error when we load the edit page.
Please share the following information to find the cause of the issue.
1. Did you face this issue in particular browser or in all browsers?
2. Essential Studio Version details.
3. Share the stackrace of a script error.
4. If possible, replicate the issue in the attached sample.
Sample: http://www.syncfusion.com/downloads/support/forum/125673/ze/SyncfusionMvcApplication29-1822198359
Regards,
Prasanna Kumar N.S.V
CR
CLAUDIO RICCARDI
September 5, 2016 01:40 PM UTC
I have tested the page with the following browsers and the problem still appears:
- Chrome (ver 52.0.2743)
- Internet Explorer (ver 11.545.10586)
In Internet Explorer I don't see the error but even if I set .Locale("it-IT"), the $ currency symbol is used.
- Essential Studio (ver. 14.2.0.26)
Stacktrace of script error
ej.culture.it-IT.min.js:1 Uncaught TypeError: ej.addCulture is not a function
(anonymous function) @ ej.culture.it-IT.min.js:1
CR
CLAUDIO RICCARDI
September 5, 2016 03:30 PM UTC
Ok, problem solved.
The script ej.web.all.min.js was out of date. After using the last version of the script everything went ok.
Thanks a lot for your support.
Best Regards.
Claudio
JK
Jayaprakash Kamaraj
Syncfusion Team
September 6, 2016 04:31 AM UTC
Hi Claudio,
We are happy to hear that your issue has been resolved.
Please get back to us if you need any further assistance.
Regards,
Jayaprakash K.
CR
CLAUDIO RICCARDI
September 6, 2016 09:22 AM UTC
Hi, Jayaprakash K.
I have another question:
I would like to have the sum of a grid's column copied into a numeric textbox.
The logical steps are these:
1) In the grid I can modify (in inline mode) either UnitPrice or Quantity and the column TotalPrice is recalculated
2) After modifications in step 1 the new values of the row are saved into database
3) The sum of the TotalPrice column is to be copied into a numerictextbox outside of the grid.
Using queryCellInfo event lets me correctly update the cell value but how can I force the data to be saved into database?
And then, how can I get the sum of the TotalPrice column so that I can copy it into the textbox?
Thanks in advance.
Claudio
JK
Jayaprakash Kamaraj
Syncfusion Team
September 7, 2016 12:40 PM UTC
Hi Claudio,
Query 1: how can I force the data to be saved into database?
We have created computed column(TotalPrice) using SQL queries. Here, we have calculated TotalPrice as EmployeeID * Freight using SQL queries. While using computed column, QueryCellInfo event is not necessary and also it will automatically calculate the value when you change the values in relational columns (EmployeeID / Freight) in Grid. Please refer to the below document
|
ALTER TABLE dbo.OrderTables DROP COLUMN TotalPrice;
GO
ALTER TABLE dbo.OrderTables ADD TotalPrice AS (EmployeeID * Freight ); |
Sample: http://www.syncfusion.com/downloads/support/forum/125673/ze/SyncfusionMvcApplication291211429029
Query 2: how can I get the sum of the TotalPrice column so that I can copy it into the textbox?
We have achieved your requirement using DataBound and ActionComplete event. In this event, we have calculated total summary value and then displayed in numeric textbox. Please refer to the below help documents, code example and sample.
Help documents for,
ActionComplete: https://help.syncfusion.com/js/api/ejgrid#events:actioncomplete
|
<div>
TotalPrice: <input id="TotalFreight" type="text" width="200" />
</div>
@(Html.EJ().Grid<object>("FlatGrid")
..
.Columns(col =>
{
..
col.Field("TotalPrice").HeaderText("TotalPrice").Width(80).Add();
col.Field("OrderDate").HeaderText("Order
}).ClientSideEvents(eve=>eve.DataBound("databound").ActionComplete("actioncomplete")))
<script type="text/javascript">
var total = 0;
function databound(args) {
total = ej.sum(this.model.dataSource.dataSource.json, "TotalPrice");
$("#TotalFreight").val(total);
}
function actioncomplete(args) {
if (args.requestType == "save" || args.requestType == "delete") {
total = ej.sum(this.model.dataSource.dataSource.json, "TotalPrice"); // here we have calculated summary for whole dataSource , if you want to display summary for current page only means use
this. model.currentViewData
$("#TotalFreight").val(total);
}
}
</script> |
Sample: http://www.syncfusion.com/downloads/support/forum/125673/ze/SyncfusionMvcApplication291211429029
Regards,
Jayaprakash k.
CR
CLAUDIO RICCARDI
September 7, 2016 03:56 PM UTC
Thanks a lot for your very professional support.
Claudio
JK
Jayaprakash Kamaraj
Syncfusion Team
September 8, 2016 04:48 AM UTC
Hi Claudio,
Thanks for the update.
Please get back to us for further assistance.
Regards,
Jayaprakash K.
SIGN IN To post a reply.
- 10 Replies
- 3 Participants
-
CR CLAUDIO RICCARDI
- Sep 1, 2016 03:08 PM UTC
- Sep 8, 2016 04:48 AM UTC