Id Returns NULL After Editing a Field

Id Returns NULL After Editing a Field

Bob WhitleyBob Whitley Posts: 3Questions: 1Answers: 0

I use Datatables 1.10.15 and Editor 1.7.2.

I am able to successfully edit values using Editor.

However, the JSON returned from the edit shows the Id of the record to be NULL. All other values return correctly.

What am I doing wrong?
.
.

HTML

<table id="tblPerClaim" class="display dbd-display-table">
    <thead>
        <tr>
            <th>Id</th>
            <th>Insured Name</th>
            <th>Claims Paid</th>
            <th>Claims Paid Prev Month</th>
            <th>Claims Paid Curr Month</th>
            <th>Payments Collected</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

Table Definition

    function PopulatePerClaim() {
        editor_perClaim = new $.fn.dataTable.Editor({
            ajax: {
                data: { '__RequestVerificationToken': antiForgeryToken },
                success: function () { },
                type: 'POST',
                url: '/DeductibleBillingDetail/ModifyDetail',
            },
            fields: [
                { label: 'Policy Number', name: 'Policy_number' },
                { label: 'Insured Name', name: 'InsuredName' },
                { label: 'Ded Remain', name: 'ClaimsPaid' },
                { label: 'Ded Remain Prev Month', name: 'ClaimsPaid_CurrentMonth' },
                { label: 'Ded Remain Vari Month', name: 'ClaimsPaid_PriorMonth' },
                { label: 'Payments Collected', name: 'PaymentsCollected' },
            ],
            idSrc: 'Id',
            table: '#tblPerClaim',
        });

        oTable_perClaim = $('#tblPerClaim').DataTable({
            ajax: {
                data: {},
                dataSrc: '',
                type: 'GET',
                url: `/GetBillingDetail/C/${clientId}/${endMonth}`,
            },
            columns: [
                {
                    className: 'dbd-details-item',
                    data: 'Id',
                },
                {
                    className: 'dbd-details-item',
                    data: null,
                    render: function (data, type, row) {
                        return 'xxxxxxxxx'
                    },
                },
                {
                    className: 'dbd-details-item ' + class_editable,
                    data: null,
                    editField: 'ClaimsPaid',
                    render: function (data, type, row) {
                        return data.ClaimsPaid.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
                    },
                },
                {
                    className: 'dbd-details-item ' + class_editable,
                    data: null,
                    editField: 'ClaimsPaid_PriorMonth',
                    render: function (data, type, row) {
                        return data.ClaimsPaid_PriorMonth.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
                    },
                },
                {
                    className: 'dbd-details-item ' + class_editable,
                    data: null,
                    editField: 'ClaimsPaid_CurrentMonth',
                    render: function (data, type, row) {
                        return data.ClaimsPaid_CurrentMonth.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
                    },
                },
                {
                    className: 'dbd-details-item ' + class_editable,
                    data: null,
                    editField: 'PaymentsCollected',
                    render: function (data, type, row) {
                        return data.PaymentsCollected.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
                    },
                },
            ],
            createdRow: function (row, data, dataIndex) { },
            language: { search: "Filter Records:" },
            order: [
                [0, 'asc'],
            ],
            pageLength: 30,
            processing: true,
            rowCallback: function (row, data) { },
            searching: true,
        });


        // editor textboxes
        $('#tblPerClaim').on('click', '.genex-datatables-editable', function (e) {
            editor_perClaim.inline(this);
        });
    }
}

Modify Data

public static DtResponse ModifyDetail(HttpRequestBase request)
{
    DtResponse response = null;

    using (var db = new Database(GenexGlobal.Datatables_DbType, GenexGlobal.ConnectionString_Genex))
    {
        response = new Editor(db, "Deductible_Staging")
            .Model<Deductible_Staging>()
            .Process(HttpContext.Current.Request)
            .Data();
    }

    return response;
}

JSON Returned after Edit

NOTE: Id is NULL but it should be 19089

{
  "draw": null,
  "data": [
    {
      "DT_RowId": "row_19089",
      "Id": null,
      "ImportDate": "/Date(1540489677830)/",
      "DeductibleOption": "C",
      "ClientId": 101,
      "Rowtype": 0,
      "Storage_id": "57133",
      "Policy_number": "xxx",
      "InsuredName": "xxx",
      "Insured_Address": "xxx",
      "Insured_State": "NY",
      "Insured_Zip": "11203",
      "Eff_Date": "04/01/2016 - 04/01/2017",
      "EndMonth": "06/30/2018",
      "ClaimNum": "xxx",
      "AccidentDate": "07/21/16",
      "State": "AR",
      "DeductibleType": "MED-IND",
      "DeductibleLimit": "1,000",
      "ClaimsPaid": 0,
      "ClaimsPaid_PriorMonth": 0,
      "ClaimsPaid_CurrentMonth": 156,
      "DeductibleMet": "NO",
      "DeductibleAmtDue": 0,
      "PaymentsCollected": 0,
      "ClaimStatus": "1",
      "PaidToDateIndem": 0,
      "PaidToDateMed": 0,
      "PaidToDateOtherExp": 12.3
    }
  ],
  "recordsTotal": null,
  "recordsFiltered": null,
  "error": null,
  "fieldErrors": [],
  "id": null,
  "meta": {},
  "options": {},
  "files": {},
  "upload": {
    "id": null
  },
  "debugSql": null,
  "cancelled": []
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Is your Id column set up as a primary key and also a serial / auto increment?

    Allan

  • Bob WhitleyBob Whitley Posts: 3Questions: 1Answers: 0

    Yes, Id is set to IDENTITY(1, 1) and it is the Primary Key of the table.

    I'm passing database type "sqlserver" into the constructor of the Database object and my connection string definition looks like this:

    <add 
      name="xxx" 
      connectionString="Data Source=xxx;Initial Catalog=Genex;Integrated Security=false;User ID=xxx;Password=xxx;" 
       providerName="System.Data.SqlClient" />
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    If you use response = new Editor(db, "Deductible_Staging", "Id") does that help? The reason I suggest that is that the default is id and while SQL Server might see that the same as Id, the C# code won't.

    It would also be worth updating to 1.7.4 or the newer 1.8.0 release.

    Thanks,
    Allan

  • Bob WhitleyBob Whitley Posts: 3Questions: 1Answers: 0

    Adding "Id" to the Editor constructor solved the problem! Thank you for the help.

This discussion has been closed.