How to submit a functional Editor test case

How to submit a functional Editor test case

AnthonyVAnthonyV Posts: 37Questions: 7Answers: 0

Link to test case:
http://live.datatables.net/quhacego/1/edit

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I would like to submit a bug report but it can only be shown using a full edit cycle.

I started an example but could not find a way to point to a live data source for data retrieval and edit.
I saw the links as the bottom of this announcement but they did not work as expected.
https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest

I used the inline editor as the starting point for my example.

https://editor.datatables.net/examples/inline-editing/simple.html

I attempted multiple data URLs:
1) Pointing to the URL used by the main site triggers a CORS error,
2) Using the URLs in the downloaded examples also fails

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    With those scripts it's better to use the data in the DOM. You should be able to use this as a starting point here: http://live.datatables.net/mohohaya/1/edit

    Colin

  • AnthonyVAnthonyV Posts: 37Questions: 7Answers: 0

    Hello Colin, thanks for that example but unfortunately I need the full server round trip.

    The issue I "think" I have found is that the result from the following two ways of getting the table data change after doing an edit. Before the edit the results are returned as an array, after they become an object.

          var legacyData = t.fnGetData(0)
          var apiData = t.api().rows().data();
    

    It is possible this is only the case when the data is server side.

    When not serverside the results are always an object so I suspect that is what is now intended. This change caught me off guard.

        // Activate an inline edit on click of a table cell
        $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {          
          var legacyData = t.fnGetData(0)
          var apiData = t.api().rows().data();
          console.log('Legacy:' + typeof legacyData);
          console.log('API:' + typeof apiData);
          editor.inline( this );
        } );
    
  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Before the edit the results are returned as an array, after they become an object.

    Yes, that is going to cause problems. The row data format returned by an edit / create command must be the same as the table’s data when it was first loaded. The value is passed straight to the DataTable, so if it is expecting an object for the row, and you give it an array, then it will fail.

    Perhaps you can show me your initialisation code and the data initially loaded and also the data on edit response?

    Allan

  • AnthonyVAnthonyV Posts: 37Questions: 7Answers: 0

    Hello Allan,

    The row data format returned by an edit / create command must be the same as the table’s data when it was first loaded.

    My server data is returned using an array but the edit structures are an array of objects as specified in the documentation. Should I be returning the edit data as an array as well?

    My application was build using the following example as starting point.
    https://datatables.net/examples/server_side/simple.html

    A sample data set is:

    {
      "iTotalRecords": 4087,
      "iTotalDisplayRecords": 4087,
      "aaData": [
        [
          "Sveti Jurij ob Šcavnici",
          "1",
          "196",
          "0",
          "a_SFG_H___81"
        ],
        [
          "Son La.",
          "2",
          "175",
          "0",
          "TPSFG_H___81"
        ],
        [
          "Ealing",
          "3",
          "26",
          "0",
          "LfSFG_H___81"
        ],
        [
          "Iklin",
          "4",
          "43",
          "0",
          "DvSFG_H___81"
        ]
      ],
      "renderedErrors": null,
      "moreData": false,
      "sMsg": null
    }
    

    Edit response was based on https://editor.datatables.net/manual/server:

    {
      "error": null,
      "fieldErrors": null,
      "data": [
        {
          "0": "Son La..",
          "1": "2",
          "2": "175",
          "3": "1",
          "4": "TPSFG_H___81"
        }
      ]
    }
    

    Configuration code is: aqagez

    The field names are "0" -> "4".

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Should I be returning the edit data as an array as well?

    Yes. 99% of Editor use cases use objects rather than arrays since it is easier to keep track of property names rather than array indexes (particularly if you add or remove a column) - which is why the documentation focuses on that almost exclusively, but you can also return an array of data in the data array on edit.

    Allan

This discussion has been closed.