Search code examples
asp.net-mvcblazorsyncfusion

Create a column without no record in the database for a Grid in syncfusion "false column" MVC


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


Solution

  • 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