Editor is not passing the ID on save. In debug mode the ID is always 0.

Editor is not passing the ID on save. In debug mode the ID is always 0.

Jason B JonesJason B Jones Posts: 12Questions: 2Answers: 1
edited October 2023 in Free community support
var BryBonusTableEditor;
var BryBonusTable;


BryBonusTableEditor = new $.fn.dataTable.Editor({
      ajax: {
          url: "/BryantBonus/LoadBryBonus",
          type: "POST",
          datatype: "json",
          error: function (xhr, error, code) {
              alert(xhr.responseText);
          }
      },
      idSrc: "id",
      fields: [
        
          {
              label: "Group #",
              name: "GroupNumber",
              type: "text"
          }
      ]



BryBonusTable = $("#BryBonusTable").DataTable({
      processing: true, // for show progress bar
      serverSide: false, // for process server side
      filter: true, // this is for disable filter (search box)
      orderMulti: true, // for disable multiple column at once
      scrollCollapse: true,
      pageLength: 15,
      paging: true,
      destroy: false,
      pageResize: true,
      autowidth: false,
      lengthMenu: [[5, 10, 15, 20, 25, 50, 100, 1000, -1], [5, 10, 15, 20, 25, 50, 100, 1000, "All"]],
      responsive: true,
      async: true,
      select: true,
      lengthChange: true,
      dom: '<"BryBonusheader">lBfrtip',
      ajax: { url: "/BryantBonus/LoadBryBonus", type: "POST", datatype: "json"},
      columns: [
          { "data": "id", visible: false },
          { "data": "BPCGRU_0" },
          { "data": "BPCNUM_0" },
          { "data": "BPCNAM_0" },
          { "data": "NUM_0" },
          { "data": "AMTNOT_0" },
          { "data": "InvBal" },
          { "data": "Late" },
          { "data": "MktMgr" },
          { "data": "INVREF_0" },
          { "data": "GroupNumber" }
      ],
      initComplete: function () {
          $('tr#filterBryBonusboxrow th').each(function () {

              var name = ($(this).text());
              var index = $(this).index();

              if ($('#binput' + $(this).index()).length === 0) {
                  $(this).html('<span> ' + name + '</span ><input id="binput' + index + '" type="text" class="form-control toggle-vis" />').css('padding-left', '4px');
              }

              $(this).on('input keyup change',
                  function () {
                      var val;

                      val = $('#binput' + $(this).index()).val();

                      var addcol = 1;

                      BryBonusTable.column(index + addcol).search(val).draw();

                  });

              //BryBonusTable.ajax.reload();
          });

          $("div.BryBonusheader").html("<h2>Bryant Bonus</h2>");
          $("div.BryBonusheader").css({ "height": "0" });
          // $('.pagination').css(" margin-top", "-3vh !important");

          //$('#BryBonusTable').DataTable().ajax.reload();
      },

      buttons: [
          { extend: "edit", text: "Edit", className: 'button-7', editor: BryBonusTableEditor },
          $.extend(true, {}, buttonselectedCommon("Excel", "BryBonusexcelSelected hide", true, columsselected, BryBonusnames), {
              extend: 'excelHtml5'
          }),

          $.extend(true, {}, buttonallCommon("Excel All", "BryBonusexcelAll", null, columsselected), {
              extend: 'excelHtml5'
          }),
          {
              extend: 'colvis',
              className: 'button-7 largerbutton',
              columns: 'th:nth-child(n+2)',
              collectionLayout: 'fixed columns',
              collectionTitle: 'Column visibility',
              postfixButtons: ['colvisRestore'],
              columnText: function (dt, idx, title) {
                  return function () { return BryBonusnames[idx] };
              }

          }
      ]
  });
}




    var formData = HttpContext.Request.Form;

    using (var db = new DataTables.Database(connectionstrings.dbtypeSqlServer, connectionstrings.Marketing))
    {
        var editor = new Editor(db, "BryantBonusTransactions", "id")
            .Model<BryantBonusTransactions>();

        var response = editor.Debug(true).Process(formData).Data();
        var jsonResult = Json(response, JsonRequestBehavior.AllowGet);
        return jsonResult;

        //return Json(editor, JsonRequestBehavior.AllowGet);

    }
       [Key]
       public int id { get; set; }
       public string BPCGRU_0 { get; set; }
       public string BPCNUM_0 { get; set; }
       public string BPCNAM_0 { get; set; }
       public string REPNAM_0 { get; set; }
       public string NUM_0 { get; set; }
       public decimal? AMTNOT_0 { get; set; }
       public decimal? InvBal { get; set; }
       public string Late { get; set; }
       public string MktMgr { get; set; }
       public string INVREF_0 { get; set; }
       public string SNS_0 { get; set; }
       public string YQTENUM_0 { get; set; }
       public string CREDAT_0 { get; set; }
       public string GroupNumber { get; set; }

Edited by Allan - formatting

This question has an accepted answers - jump to answer

Answers

  • Jason B JonesJason B Jones Posts: 12Questions: 2Answers: 1
    edited October 2023

    Sorry for the poor formatting. I use datatables in almost all my pages and even copied this one from another page where the editor is working. I just changed the field names . This is a process I have done many times but for some reason this time it will not save and I cannot figure out why.

    The debug is passing a 0 for the ID

  • Jason B JonesJason B Jones Posts: 12Questions: 2Answers: 1
    Answer ✓

    I was able to figure it out. I forgot to add
    table: "#BryBonusTable",

    to the editor.

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin

    Thanks for the update - good to hear you've got it working!

    Allan

Sign In or Register to comment.