This is a migrated thread and some comments may be shown as answers.

problems with dynamic grid

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Constantin
Top achievements
Rank 1
Constantin asked on 14 Apr 2021, 04:07 PM

Hi guys! I really need your help!

It is necessary to make a dynamic grid with the ability to edit cells. The grid layout appears. Column names are visible. Data is not loaded into the grid. There is an error in the browser console:"Uncaught SyntaxError: unexpected token: numeric literal" kendo.all.js:63353:40. I can’t cope with this error ...

View:

@model System.Data.DataTable
 
@{
    var id = Model.Columns[0].ColumnName;
    var templateName = "String";
}
 
@(Html.Kendo().Grid<dynamic>()
    .Name("Grid")
    .Columns(columns =>
    {
        foreach (System.Data.DataColumn column in Model.Columns)
        {
 
            switch (column.DataType.ToString())
            {
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                    templateName = "Integer";
                    break;
                case "System.Decimal":
                case "System.Double":
                case "System.Float":
                    templateName = "Number";
                    break;
                case "System.String":
                    templateName = "NotEditable";
                    break;
            }
 
            if (column.ColumnName == id)
            {
                templateName = "NotEditable";
            }
 
            columns.Bound(column.ColumnName).Title(column.Caption).EditorTemplateName(templateName).EditorViewData(new { name = id });
        }
    })
    .ToolBar(toolbar => {toolbar.Save(); })
    .Editable(ed=>ed.Mode(GridEditMode.InCell))
    .Scrollable()
    .DataSource(dataSource => dataSource.Ajax()
        .Batch(true)
        .Model(model =>
        {
            model.Id(id);
            foreach (System.Data.DataColumn column in Model.Columns)
            {
                var field = model.Field(column.ColumnName, column.DataType);
                if (column.ColumnName == id || column.ColumnName == "BusName")
                {
                    field.Editable(false);
                }
            }
        })
        .Read("Read", "Project")
        .Update("Update", "Project")
    )
    )

Controller:

public ActionResult Index()
        {
            DataTable proj = new DataTable("table");
            proj.Columns.Add()...;
            proj.Rows.Add()
 
            return View(proj);
        }

In debug mode, the Read method does not enter ...

kendo ver. 2018.1.221.545

 

Please tell me what to do. 2 days I can not solve this problem

 

 

1 Answer, 1 is accepted

Sort by
0
Constantin
Top achievements
Rank 1
answered on 16 Apr 2021, 10:10 AM

fixed:

when generating columns "ColumnName" shouldn't be a number.

not allowed: "1"

possible, "_1"

 

 

 

var column = new DataColumn();
{
 column.Caption = "red air";
 column.ColumnName = "id";   <<<<id shouldn't be a number.
 column.DataType = typeof(int);
}
dt.Columns.Add(column);

Tags
Grid
Asked by
Constantin
Top achievements
Rank 1
Answers by
Constantin
Top achievements
Rank 1
Share this question
or