Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
385
DataBind JSON Error
posted

Hello,

I have a problem when calling igGrid("Databind') method on igGrid to refresh Data after having add a new record.

Here is the configuration of igGrid :

 <%= Html.Infragistics().Grid(Model.ListeSites).ID("Sites").DataSourceUrl(Url.Action("GetListe")).AutoCommit(true).PrimaryKey("Site").AutoGenerateColumns(false).EnableHoverStyles(false).Columns(column =>
    {
        column.For(x => x.Site).HeaderText("Site").Width("45");
        column.For(x => x.Description).HeaderText("Description").Width("150");
        column.For(x => x.Nom).HeaderText("Nom").Width("100");
        column.For(x => x.Adresse1).HeaderText("Adresse 1").Width("100");
        column.For(x => x.Adresse2).HeaderText("Adresse 2").Width("100");
        column.For(x => x.CodePostal).HeaderText("Code postal").Width("100");
        column.For(x => x.Ville).HeaderText("Ville").Width("90");
        column.For(x => x.Contact).HeaderText("Contact").Width("90");
        column.For(x => x.Telephone).HeaderText("Téléphone").Width("90");
        column.For(x => x.Siret).HeaderText("Siret").Width("90");
    })
        .Features(features =>
        {
            features.Paging().Type(OpType.Local).PageSize(20);
            features.Sorting().Mode(SortingMode.Single);
            if (User.IsInRole(((int)Andra.PriscaND.Business.Model.RoleName.Administrateur).ToString()))
            {
                features.Updating()
                    .EnableAddRow(true)
                    .EnableDeleteRow(true)
                    .EditMode(GridEditMode.Row)
                    .ColumnSettings(settings =>
                    {
                        settings.ColumnSetting().ColumnKey("Site").ReadOnly(false).EditorType(ColumnEditorType.Text).Required(true).Validation(true)
                                                                    .EditorOptions(@"validatorOptions: {requiredMessage: 'Site obligatoire'}, maxLength:3");
                        settings.ColumnSetting().ColumnKey("Description").EditorType(ColumnEditorType.Text).Required(true)
                            //.EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation', onChange: true}");
                                                                    .EditorOptions(@"validatorOptions: {requiredMessage: 'Description obligatoire'}, maxLength:250");
                        settings.ColumnSetting().ColumnKey("Nom").ReadOnly(false).EditorOptions("maxLength:50");
                        settings.ColumnSetting().ColumnKey("Adresse1").ReadOnly(false).EditorOptions("maxLength:50");
                        settings.ColumnSetting().ColumnKey("Adresse2").ReadOnly(false).EditorOptions("maxLength:50");
                        settings.ColumnSetting().ColumnKey("CodePostal").ReadOnly(false).EditorOptions("maxLength:20");
                        settings.ColumnSetting().ColumnKey("Ville").ReadOnly(false).EditorOptions("maxLength:50");
                        settings.ColumnSetting().ColumnKey("Contact").ReadOnly(false).EditorOptions("maxLength:50");
                        settings.ColumnSetting().ColumnKey("Telephone").ReadOnly(false).EditorOptions("maxLength:20");
                        settings.ColumnSetting().ColumnKey("Siret").ReadOnly(false).EditorOptions("maxLength:14");
                    });
            }
        }).DataBind().Render()

Then the JS code that generates error :

 $("#Sites").igGrid("dataBind");

Here is the error from Firefox :

Error: There was an error parsing/evaluating the JSON string: JSON.parse: unexpected character
http://localhost:49944/Scripts/infragistics.js
Line 51

And loading panel remains turning around and nothing more happens.

Tank's by advance.

Regards,

Hardis

Parents
  • 23953
    Offline posted

    Hi Hardis,

    In your code you're binding to data in two ways at the same time.

    First is by passing a IEnumerable to the Grid method and calling DataBind() with this code:

    Code Snippet
    1. .Grid(Model.ListeSites)
    2. .DataBind()

    When you use DataBind() you're forcing igGrid to bind to data on the server side and the data is then serialized as part of the igGrid JavaScript code and then send to the browser.

     

    Second is by using DataSourceUrl(). When using DataSourceUrl() alone igGrid configuration code is serialized and send to the browser. When this code is executed in the browser the igGrid makes and AJAX call to the server to get the data.

    At the end igGrid doesn't know how to re-bind.

    So in order to fix your code you have to choose which data bind method you will use. I don't see UpdateUrl in your grid configuration so I guess you're using your custom method to post the new records of the grid to the server. If this is your situation then you should choose DataSourceUrl() data bind method, so you should remove .DataBind() from your grid initialization code OR do not pass anything to the View in your controller:

    Example:

     

    Code Snippet
    1. public ActionResult Index()
    2. {
    3.     return View();
    4. }

     

    Hope this helps,

    Martin Pavlov

    Infragistics, Inc.

Reply Children