Editor Inline, input sent empty even he has value in first on edit

Editor Inline, input sent empty even he has value in first on edit

eyal_hbeyal_hb Posts: 73Questions: 25Answers: 0

Editor Inline, input sent empty even he has value before edit
this wired because i have the same table but with diffrent parmas in other view that working fine with editor inline
in this view when i want to edit, Air_Fare_T.AirFare_Code_T always sent empty on inline edit

i have this serverSide code:

 [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        public ActionResult GetDataAirFareTrip(int id)
        {
            var settings = Properties.Settings.Default;
            var formData = HttpContext.ApplicationInstance.Context.Request;

            using (var db = new DataTables.Database(settings.DbType, settings.DbConnection))
            {
                var editor = new DataTables.Editor(db, "Air_Fare_T", "Air_Fare_T_Id");
                editor.Where(q =>
                    q.Where("Air_Fare_T.AirFare_Costing_T_Id", "(SELECT AirFare_Costing_T_Id FROM Air_Fare_T WHERE AirFare_Costing_T_Id= " + id + ")", "IN", false)
                );
                editor.Model<ViewModel.AirFareTripEditorVM>("Air_Fare_T")
                   .Field(new Field("Air_Fare_T.Air_Fare_T_Id")
                    .Validator(Validation.Numeric())
                    .Set(false)
                )
                 .Field(new Field("Air_Fare_T.AirFare_Costing_T_Id")
                    .Validator(Validation.Numeric())
                )
                .Field(new Field("Air_Fare_T.AirFare_Code_T").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null))
                )
                .Field(new Field("Air_Fare_T.Air_Fare_T_Type").Xss(true)
                .Validator(Validation.Numeric())
                .Options(new Options()
                        .Table("AirFare_Trip_Type")
                        .Value("AirFare_Trip_Type_Id")
                        .Order("AirFare_Trip_Type.AirFare_Trip_Type_Id")
                        .Label("AirFare_Trip_Type_Name")
                )
                .SetFormatter(Format.IfEmpty(null))
                )
                .Field(new Field("Air_Fare_T.Air_Fare_T_Currency").Xss(true)
                .Validator(Validation.Numeric())
                .Options(new Options()
                        .Table("CurrencyCosting")
                        .Value("Currency_Id")
                        .Order("CurrencyCosting.Currency_Id")
                        .Label("Currency_Name")
                        )
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_Price").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_PAX").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_Total").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)));
                editor.Model<ViewModel.CostingAirlineEditorVM>("Costing_Airlines")
                .LeftJoin("Costing_Airlines", "Costing_Airlines.Airline_Id", "=", "Air_Fare_T.AirFare_Code_T");
                editor.Model<ViewModel.AirFareTripTypeEditorVM>("AirFare_Trip_Type")
                .LeftJoin("AirFare_Trip_Type", "AirFare_Trip_Type.AirFare_Trip_Type_Id", "=", "Air_Fare_T.Air_Fare_T_Type");
                editor.Model<ViewModel.CurrencyCostingEditorVM>("CurrencyCosting")
                .LeftJoin("CurrencyCosting", "CurrencyCosting.Currency_Id", "=", "Air_Fare_T.Air_Fare_T_Currency");

                // Post functions
                editor.PreCreate += (sender, e) =>
                {
                    var totalVal = getTotalValTrip(e.Values, id);
                    editor.Field("Air_Fare_T.Air_Fare_T_Total").SetValue(totalVal[1]);
                    editor.Field("Air_Fare_T.Air_Fare_T_Price").SetValue(totalVal[0]);


                };
                editor.PreEdit += (sender, e) =>
                {
                    var totalVal = getTotalValTrip(e.Values, id);
                    editor.Field("Air_Fare_T.Air_Fare_T_Total").SetValue(totalVal[1]);
                    editor.Field("Air_Fare_T.Air_Fare_T_Price").SetValue(totalVal[0]);


                };
                editor.Process(formData.Unvalidated.Form);
                DtResponse data = editor.Data();
                return Json(data, JsonRequestBehavior.AllowGet);
            }
        }

Answers

  • eyal_hbeyal_hb Posts: 73Questions: 25Answers: 0

    this is the view code:

    <script>
    
        var editor = new $.fn.dataTable.Editor({
            ajax: '@Url.Action("GetDataAirFareTrip", "AirFare")?id='+@ViewBag.CostingId_AirFare+'',
            table: "#air_fare_table",
            fields: [
                {
                    name: "Air_Fare_T.AirFare_Costing_T_Id",
                    type: "hidden",
                    default: '@ViewBag.CostingId_AirFare',
    
    
                },
                {
                    name: "Air_Fare_T.AirFare_Code_T",
                    label: "קוד חברת תעופה:",
                    type: "select2",
                    initialValue: true,
                    opts: {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "minimumInputLength": 1,
                        "placeholder": {
                            "id": "",
                            "text": "בחרו קוד חברת תעופה"
                        },
                        ajax: {
                            url: '@Url.Action("getAirLineCodes", "SystemConstants")',
                            dataType: 'json',
                            data: function (params) {
                                return {
                                    Prefix: params.term,
                                };
                            },
                            processResults: function (data) {
                                return {
                                    results: $.map(data, function (item) {
                                        return {
                                            text: item.Name,
                                            id: item.Id
                                        }
                                    })
                                };
                                cache: true
                            },
                        }
                    }
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Type",
                    label: "סוג ערך:",
                    type: "select2",
                    "opts": {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "placeholder": {
                            "id": "",
                            "text": "בחרו סוג ערך"
                        },
                    },
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Currency",
                    label: "מטבע:",
                    type: "select2",
                    "opts": {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "placeholder": {
                            "id": "",
                            "text": "בחרו סוג מטבע"
                        },
                    }
    
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Price",
                    label: "עלות:",
                    type: "text",
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_PAX",
                    label: "כמות אנשים:",
                    type: "text",
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Total",
                    type: "hidden",
                },
            ],
            i18n: DTE_i18n
        });
    
        var airFareTable = $('#air_fare_table').DataTable({
            dom: "Bt",
            "ajax": {
                "url": '@Url.Action("GetDataAirFareTrip", "AirFare")?id='+@ViewBag.CostingId_AirFare+'',
            },
            "language": {
                "url": "@HttpContext.Current.Application["VirDir"]/media/language/de_HEB.json"
            },
            "footerCallback": function (row, data, start, end, display) {
                var api = this.api(), data;
                for (var i = 1; i <= api.columns().count() - 1; i++) {
                    // Remove the formatting to get integer data for summation
                    var intVal = function (i) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '') * 1 :
                            typeof i === 'number' ?
                                i : 0;
                    };
    
                    // Total over all pages
                    total = api
                        .column(5)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    ///person for trip
                    person = api
                        .column(4)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    // Total over this page
                    pageTotal = api
                        .column(5, { page: 'current' })
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    // Update footer
                    $(api.column(5).footer()).html(
                        '$' + pageTotal
                    );
    
                    $('tr:eq(1) th:eq(' + i + ')', api.table().footer()).html(pageTotal / person);
                }
            },
            keys: {
                columns: ':not(:first-child)',
                editor: editor
            },
            select: true,
            columns: [
                { data: "Costing_Airlines.Airline_Code" },
                { data: "AirFare_Trip_Type.AirFare_Trip_Type_Name" },
                { data: "CurrencyCosting.Currency_Name"},
                { data: "Air_Fare_T.Air_Fare_T_Price" },
                { data: "Air_Fare_T.Air_Fare_T_PAX" },
                { data: "Air_Fare_T.Air_Fare_T_Total"},
    
    
            ],
            buttons: {
                buttons: [
                    {
                        extend: "create",
                        text: "new",
                        editor: editor,
                        className: "datatableB"
                    },
                    {
                        extend: "remove",
                        text: "delete",
                        editor: editor,
                        className: "datatableB"
                    }
    
                ],
                dom: {
                    button: {
                        tag: "button",
                        className: "btn"
                    },
                }
            }
        });
    
        $('#air_fare_table').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
                submit: 'allIfChanged'
            });
        });
    
    
    
    </script>
    
  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin

    Hi,

    Don't combine:

            keys: {
                columns: ':not(:first-child)',
                editor: editor
            },
    

    with:

        $('#air_fare_table').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
                submit: 'allIfChanged'
            });
        });
    

    Drop the second block - let KeyTable handle the inline editing itself. If you want allIfChanged add:

    formOptions: {
      inline: {
        submit: 'allIfChanged'
      }
    }
    

    to your Editor initialisation object.

    Regards,
    Allan

  • eyal_hbeyal_hb Posts: 73Questions: 25Answers: 0
    edited February 13

    hey Allan, thanks for the replay
    i change as you recommend, but still its not working

  • allanallan Posts: 51,411Questions: 1Answers: 7,752 Site admin

    If you could give me a link to the page I'll debug it directly.

    Thanks,
    Allan

  • eyal_hbeyal_hb Posts: 73Questions: 25Answers: 0

    hey Allen, i think i figure out what happens , if i use allIfChanged in submit this is delete the selected2 ajax remote value, if i cancel this it work.

    inline: {
                   submit: 'allIfChanged',
     }
    

    what to do? i must get 3 field when one field is changed ?
    to make some field-total field calculation

  • colincolin Posts: 8,013Questions: 0Answers: 1,348

    Please link to the page as Allan suggested, then we can take a look.

    Colin

Sign In or Register to comment.