Inline edit of same row twice - ID not being sent on the second request

Inline edit of same row twice - ID not being sent on the second request

bkatesbkates Posts: 35Questions: 5Answers: 0

I have a standard data table with an inline Editor:

editor = new $.fn.dataTable.Editor( {
                ajax: /path/to/my/controller
                table: #myTable
                idSrc: "id",
                fields: [ { name: "weekNumber" }, 
                          { name: "weekSalesAmount"},
                          { name: "salesWeek"},
                          { name: "gameOnSale" },
                          { name: "fiscalYear" },
                          { name: "fiscalYearWeek" },
                          { name: "calendarYear" },
                          { name: "calendarYearWeek" },
                          { name: "quarter" },
                          { name: "month" }
                     ]
         } );
         
        $('#myTable').on( 'click', 'tbody td', function (e) {
            editor.inline( this );
        } );

var table = $('#myTable').DataTable( {
                "data": myData,
                "columns":
                  [
                    { data: "weekNumber" },
                    { data: "weekSalesAmount" },
                    { data: "salesWeek" },
                    { data: "gameOnSale" },
                    { data: "fiscalYear" },
                    { data: "fiscalYearWeek" },
                    { data: "calendarYear" },
                    { data: "calendarYearWeek" },
                    { data: "quarter" },
                    { data: "month" }
                  ]
                } );    // table

Updating a row the first time always works, e.g. this form data gets posted to the server:

action:edit
data[weekNumber]:1
data[weekSalesAmount]:$1,800
data[salesWeek]:2012-01-28
data[gameOnSale]:Yes
data[fiscalYear]:2012
data[fiscalYearWeek]:43
data[calendarYear]:2012
data[calendarYearWeek]:4
data[quarter]:1
data[month]:January
id:111101

And I'm getting a response of:

{"id":111101,"versionNum":0,"weekNumber":1,"salesWeek":"2012-01-28","gameOnSale":"No","fiscalYear":2012,"fiscalYearWeek":43,"calendarYear":2012,"calendarYearWeek":4,"quarter":1,"month":"January","DT_RowId":"111101","weekSalesAmount":"$1,800"}

I try and update the same row again, this is the form data posted to the server:

action:edit
data[weekNumber]:1
data[weekSalesAmount]:$1,800
data[salesWeek]:2012-01-28
data[gameOnSale]:No
data[fiscalYear]:2012
data[fiscalYearWeek]:43
data[calendarYear]:2012
data[calendarYearWeek]:4
data[quarter]:1
data[month]:January

Note the ID is missing. The request fails: Status Code:400 Bad Request

Any suggestions?

Thanks.

-Brian

Answers

  • bkatesbkates Posts: 35Questions: 5Answers: 0

    It wasn't working because I wasn't wrapping the data with "row". I added that and no problems.

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

    Hi,

    Good to hear you got it sorted out!

    Allan

  • tweisstweiss Posts: 1Questions: 0Answers: 0

    I have the same problem. Could you please explain, how you solved that?

    Best regards.

  • bkatesbkates Posts: 35Questions: 5Answers: 0

    Your JSON response must include "row", e.g.

    {
    "row": {
    "DT_RowId": "row_43",
    "first_name": "Brunob",
    "last_name": "Nash",
    "position": "Software Engineer",
    "email": "b.nash@datatables.net",
    "office": "London",
    "extn": "6222",
    "age": "38",
    "salary": "163500",
    "start_date": "2011-05-03"
    }
    }

    I was only sending:

    {
    "DT_RowId": "row_43",
    "first_name": "Brunob",
    "last_name": "Nash",
    "position": "Software Engineer",
    "email": "b.nash@datatables.net",
    "office": "London",
    "extn": "6222",
    "age": "38",
    "salary": "163500",
    "start_date": "2011-05-03"
    }

    (NOTE: there is no row)

This discussion has been closed.