Editor Datatables - Requested unknown parameter 'Id' for row 142, column 0

Editor Datatables - Requested unknown parameter 'Id' for row 142, column 0

Salman411Salman411 Posts: 2Questions: 1Answers: 0

I am using Editor Datatables to show records from my Oracle db in ASP.NET MVC. I have successfully implemented datatables. But the problem occurs when I try to inline edit a column and post back JSON from my controller to datatable.

HTML:

<div>
    <table class="display" cellspacing="0" id="trx_detail_tbl">
                                <thead>
                                    <tr>
                                        <th>Id</th>
                                        <th>Cutomer Id</th>
                                        <th>Customer Name</th>
                                        <th>Cheque Id</th>
                                        <th>Receipt Number</th>
                                        <th>Receipt Date</th>
                                        <th>Maturity Date</th>
                                        <th>Amount</th>
                                        <th>Currency</th>
                                        <th>Functional Amount</th>
                                        <th>Transaction Date</th>
                                        <th>Status</th>
                                        <th>Status Date</th>
                                        <th>Clearing Status</th>
                                        <th>Clearing Date</th>
                                        <th>Discounted Amount</th>
                                        <th>Comments</th>
                                        <th>Discounted</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>

Javascript:

   ```

function getTransactionDetails(id) {
$("#trx-detail-div").show();

    editor = new $.fn.dataTable.Editor({
        ajax: {
            "url": "/ChequeDiscounting/SaveTransactionDetails",
            "type": "POST",
            "data": JSON.stringify(),
            "dataType": "json"
        },
        table: "#trx_detail_tbl",
        idSrc: 'ChequeId',
        fields: [{
            label: "Functional Amount:",
            name: "FunctionalAmount"
        }, {
            label: "Transaction Date:",
            name: "TransactionDate",
            type: "datetime"
        }, {
            label: "Status:",
            name: "Status",
            type: "select",
            options: [
                { label: 'Select Status', value: '0' },
                { label: 'Approved', value: '1' },
                { label: 'Rejected', value: '2' },
                { label: 'Bounced', value: '3' }
            ]
        }, {
            label: "Status Date:",
            name: "StatusDate",
            type: "datetime"
        }, {
            label: "Clearing Status:",
            name: "ClearingStatus",
            type: "select",
            options: [
                { label: 'Select Clearing Status', value: '0' },
                { label: 'Cleared', value: '1' },
                { label: 'Uncleared', value: '2' }
            ]
        }, {
            label: "Clearing Date:",
            name: "ClearingDate",
            type: "datetime"
        }, {
            label: "Discounted Amount:",
            name: "DiscountedAmount"
        }, {
            label: "Comments:",
            name: "Comments"
        }],
        formOptions: {
            inline: {
                onBlur: 'submit'
            }
        }
    });

    trxDetailTable = $('#trx_detail_tbl').removeAttr('width').DataTable({
        "stateSave": true,
        "scrollX": true,
        "filter": true,
        "ajax": {
            "url": "/ChequeDiscounting/GetTransactionDetails/" + id,
            "type": "POST",
            "dataType": "json"
        },
        "columns": [
            { "data": "Id" },
            { "data": "CustomerId" },
            { "data": "CustomerName" },
            { "data": "ChequeId" },
            { "data": "ReceiptNumber" },
            { "data": "ReceiptDate" },
            { "data": "MaturityDate" },
            { "data": "Amount" },
            { "data": "Currency" },
            { "data": "FunctionalAmount" },
            { "data": "TransactionDate" },
            { "data": "Status" },
            { "data": "StatusDate" },
            { "data": "ClearingStatus" },
            { "data": "ClearingDate" },
            { "data": "DiscountedAmount" },
            { "data": "Comments" },
            {
                "data": null,
                "render": function (data, type, row) {
                    if (row.IsDiscounted == 1)
                        return '<td>Already Discounted</td>';
                    else
                        return '<a onClick=checkDiscount(' + row.ChequeId + ');>Discounted</a>';
                }
            },
        ],
        "columnDefs": [
            //{
            //    "defaultContent": "-",
            //    "targets": "_all"
            //},
            { "width": 70, "targets": 0 },
            { "width": 300, "targets": 1 },
            { "width": 100, "targets": 2 },
            { "width": 100, "targets": 3 },
            { "width": 100, "targets": 4 },
            { "width": 100, "targets": 5 },
            { "width": 100, "targets": 6 },
            { "width": 110, "targets": 7 },
            { "width": 130, "targets": 8 },
            { "width": 110, "targets": 9 },
            { "width": 110, "targets": 10 },
            { "width": 100, "targets": 11 },
            { "width": 110, "targets": 12 },
            { "width": 100, "targets": 13 },
            { "width": 140, "targets": 14 },
            { "width": 200, "targets": 15 },
            { "width": 100, "targets": 16 },
        ],
        "fixedColumns": true,
        "order": [1, 'asc']
    });

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

Controller:

[HttpPost]
public ActionResult SaveTransactionDetails(FormCollection form)
{
bool flag = false;

        int chequeId = Convert.ToInt32(form.Keys[1].Split('[')[1].Split(']').First());
        string columnName = form.Keys[1].Split('[')[2].Split(']').First();

        int functionalAmount;
        string transactionDate;
        string status;
        string statusDate;
        string clearingStatus;
        string clearingDate;
        int discountedAmount;
        string comments;
        string query;
        string serializedData = "";

        List<CustomerTransactionModel> tempList = new List<CustomerTransactionModel>();

        var customerTrxDetail = Shared.CustomerTransactionDetailsList.Where(a => (a.ChequeId == chequeId) && a.Id > 0).FirstOrDefault();
        var newCustomerTrxDetail = Shared.CustomerTransactionDetailsList.Where(a => a.ChequeId == chequeId).FirstOrDefault();

        if (columnName == "FunctionalAmount")
        {
            functionalAmount = Convert.ToInt32(form[1]);

            if (customerTrxDetail != null)
            {
                customerTrxDetail.FunctionalAmount = functionalAmount;
                tempList.Add(customerTrxDetail);
                serializedData = JsonConvert.SerializeObject(tempList);
            }
          }

        return Json(new { data = serializedData });
    }

Model:

public class CustomerTransactionModel
{
public int Id { get; set; }

public string ReceiptNumber { get; set; }

public string ReceiptDate { get; set; }

public int Amount { get; set; }

public string Currency { get; set; }

public int ChequeId { get; set; }

public string CustomerName { get; set; }

public int CustomerId { get; set; }

public string MaturityDate { get; set; }

public int FunctionalAmount { get; set; }

public string TransactionDate { get; set; }

public string Status { get; set; }

public string StatusDate { get; set; }

public string ClearingStatus { get; set; }

public string ClearingDate { get; set; }

public int DiscountedAmount { get; set; }

public string Comments { get; set; }

public int IsDiscounted { get; set; }

}
```

Issue is whenever I try to inline edit a column It gives me following error: DataTables warning: table id=trx_detail_tbl - Requested unknown parameter 'Id' for row 142, column 0. For more information about this error, please see http://datatables.net/tn/4

Stuck in this error for almost a day. Can someone please help me?``

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.