0
votes

I am generating a grid from a view querying multiple tables. I need to add a column that will be edited by the user by entering an amount so that the row can save as a new record in a couple of tables. This is why the column is not really generated in the database, since there is not really a record that contains that amount.

@(Html.EJ().Grid<object>("ITEMS_PRESUPUESTOGrid")
    .Datasource(ds => ds.URL("GetOrderData_VISTA_ITEMS_PRESUPUESTO_ACTIVO").Adaptor(AdaptorType.UrlAdaptor))
    //.AllowScrolling()
    //.ScrollSettings(col => { col.Width(520).Height(300).EnableVirtualization(true); })
    .AllowPaging()
    .AllowFiltering()
    .QueryString("COD_SUBCAPITULO")
    .Locale("es-CO")
    .AllowResizeToFit(true)
    .AllowResizing(false)
    .AllowMultiSorting()
    .AllowSorting()
    .PageSettings(page => page.PageSize(7))
    .ClientSideEvents(eve => eve.ToolbarClick("clickedderecha"))
    .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Normal); })
    .ClientSideEvents(e => e.Load("load_VISTA_ITEMS_PRESUPUESTO_ACTIVOGrid").Create("create_grid_ITEMS_PRESUPUESTOGrid").ActionBegin("inicio").ActionBegin("inicio_grid_VISTA_ITEMS_PRESUPUESTO_SIN_CONTRATOGrid").Create("create_grid_VISTA_ITEMS_PRESUPUESTO_SIN_CONTRATOGrid"))
    .ToolbarSettings(toolbar =>
    {
        toolbar.ShowToolbar().ToolbarItems(items =>
        {
            items.AddTool(ToolBarItems.Search);
        });
    }).Columns(col =>
    {
        
        col.Field("COD_ITEM").HeaderText("CÓDIGO").IsPrimaryKey(true).Visible(true).Add();
        col.Field("NOMBRE").HeaderText("NOMBRE").Add();
        col.Field("CANTIDAD").HeaderText("C. PRESU.").Add();
        col.HeaderText("C. A REG").EditType(EditingType.NumericEdit).Add();
})

to edit the data in the template (client side) I am trying with: .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Normal); }) but i don't know how to see these changes reflected. enter image description here after editing it is not saving the entered value.

The column in reference is the last one. At this time, first it is not taking the default value and it is not saving the value that I enter when I edit the column. I have not yet created the function to save the data in the database because first I want to get to modify the data in the template.

This is the code for the database view:


CREATE VIEW [dbo].[VISTA_ITEMS_PRESUPUESTO_ACTIVO]
AS
SELECT        
dbo.ITEMS_PRESUPUESTO.COD_ITEM, 
dbo.ITEMS_PRESUPUESTO.NOMBRE, dbo.ITEMS_PRESUPUESTO.CANTIDAD,
dbo.PRESUPUESTOS_ITEM_PRESUPUESTO.COD_PRESUPUESTO_ITEM_PRESUPUESTO, 
dbo.PRESUPUESTOS_ITEM_PRESUPUESTO.COD_PRESUPUESTO, 
dbo.PRESUPUESTOS.COD_PROYECTO, 
0 AS CANTIDAD_ACTIVIDAD
FROM            
dbo.ITEMS_PRESUPUESTO INNER JOIN
dbo.PRESUPUESTOS_ITEM_PRESUPUESTO ON dbo.ITEMS_PRESUPUESTO.COD_ITEM = dbo.PRESUPUESTOS_ITEM_PRESUPUESTO.COD_ITEM 
INNER JOIN
dbo.PRESUPUESTOS ON dbo.PRESUPUESTOS_ITEM_PRESUPUESTO.COD_PRESUPUESTO = dbo.PRESUPUESTOS.COD_PRESUPUESTO 
INNER JOIN
dbo.PROGRAMAS ON dbo.PROGRAMAS.COD_PROYECTO = dbo.PRESUPUESTOS.COD_PROYECTO
WHERE        (dbo.ITEMS_PRESUPUESTO.COD_ESTADO_ITEM_PRESUPUESTO = 1) AND (dbo.PRESUPUESTOS.COD_ESTADO_PRESUPUESTO = 5)

and this is the controller:

public ActionResult GetOrderData_VISTA_ITEMS_PRESUPUESTO_ACTIVO(DataManager dm)
        {
            IEnumerable DataSource = db.VISTA_ITEMS_PRESUPUESTO_ACTIVO.ToList();
            DataOperations ds = new DataOperations();
            List<string> str = new List<string>();
            db.Configuration.ProxyCreationEnabled = false;
            db.Configuration.LazyLoadingEnabled = false;
            return Json(new { result = DataSource }, JsonRequestBehavior.AllowGet);
        }

if someone can help me I am very grateful

2
This question is not very clear. Can you add more information about how you are editing the values, how you are posting them to the database (this code) and how you are trying to save the records? - Mark Cooper
Done, already add more information, thanks for the suggestion - jrco1989

2 Answers

0
votes

strong text

I found a solution in the official documentation

}).Columns(col => {    
col.Type("checkbox").HeaderText("").Field("").Width("60").AllowFiltering(false).AllowSorting(false).Add();
col.Field("COD_ITEM").HeaderText("CÓDIGO").IsPrimaryKey(true).Visible(false).col.Field("NOMBRE").HeaderText("NOMBRE").Add();
col.Field("CANTIDAD").HeaderText("C. DISPONIBLE").Add();
col.HeaderText("C. ADD").Template("<input value=0 />").Add();

I added two editable fields, the check one and an input, I share the links to expand the information: https://help.syncfusion.com/aspnetmvc/grid/columns?cs-save-lang=1&cs-lang=razor https://help.syncfusion.com/aspnetmvc/grid/editing?_ga=2.162224380.1153013492.1605824141-52632355.1601061767#default-column-values-on-add-new

0
votes

Based on your sample, the last column has no field properties. So the last column displays the empty value. Based on your query, you are using Multiple table to generate grid. So we suggest that you use foreign key column. Please refer to the below code snippet:

Your code:

 col.Field("NOMBRE").HeaderText("NOMBRE").Add(); 
col.Field("CANTIDAD").HeaderText("C. PRESU.").Add(); 
 col.HeaderText("C. A REG").EditType(EditingType.NumericEdit).Add();
.
 

Modified code:

col.Field("OrderID").HeaderText("CÓDIGO").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();        col.Field("Freight").HeaderText("NOMBRE").TextAlign(TextAlign.Right).EditType(EditingType.NumericEdit).Width(75).Format("{0:C}").Add(); 
col.Field("ShipCity").HeaderText("C. PRESU.").Width(80).Add(); 
col.Field("EmployeeID").HeaderText("C. A REG").ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").DataSource(ViewBag.data).TextAlign(TextAlign.Right).Width(90).Add();
 

Please refer to the below help documentation: https://help.syncfusion.com/aspnetmvc/grid/columns#foreign-key-column

Please refer to the modified sample: https://www.syncfusion.com/downloads/support/directtrac/304148/ze/Grid-sample-627225723