how i save columns reordering state in data base? please explain allan.

how i save columns reordering state in data base? please explain allan.

jatin gajerajatin gajera Posts: 60Questions: 23Answers: 0

how i save columns reordering state in database?
how i sent column order in database???

This question has an accepted answers - jump to answer

Answers

  • jvretamerojvretamero Posts: 26Questions: 0Answers: 3
    Answer ✓

    Check the stateSaveCallback.

  • OpticNectarOpticNectar Posts: 4Questions: 1Answers: 0

    It would be great if this was added to the RowReordering section with some examples etc. Took me hours to figure this out since there are no docs anywhere saying this.

  • OpticNectarOpticNectar Posts: 4Questions: 1Answers: 0

    @jvretamero How do you get the data for each column? It doesn't seem to be in the data field.

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    RowReordering doesn't use the state saving in DataTables - which is why you won't find that information in the documentation. If you want to make the changes from RowReorder permanent, you need to save the changes to your data source, like in this Editor example.

    Allan

  • OpticNectarOpticNectar Posts: 4Questions: 1Answers: 0

    @allan I tried something like that example and it doesn't work properly at all. Are there any examples on actually saving after reordering the row? The docs are all over the place.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    In the example the Order column is used to keep track of the order. Do you have a column similar?

    Take a look at the example by going to the "Ajax load" tab. This may be in a different order but you should see something like this for the first two records:

    {
      "data": [
        {
          "DT_RowId": "row_1",
          "title": "The Final Empire: Mistborn",
          "author": "Brandon Sanderson",
          "duration": "1479",
          "readingOrder": "1"
        },
        {
          "DT_RowId": "row_2",
          "title": "The Name of the Wind",
          "author": "Patrick Rothfuss",
          "duration": "983",
          "readingOrder": "2"
        },
    

    Go to the "Ajax data" tab then reorder the first two rows. The result will look something like this:

    Data Sent:

    action=edit
    data[row_2][readingOrder]=1
    data[row_1][readingOrder]=2
    

    Server response:

    {
      "data": [
        {
          "DT_RowId": "row_2",
          "title": "The Name of the Wind",
          "author": "Patrick Rothfuss",
          "duration": "983",
          "readingOrder": "1"
        },
        {
          "DT_RowId": "row_1",
          "title": "The Final Empire: Mistborn",
          "author": "Brandon Sanderson",
          "duration": "1479",
          "readingOrder": "2"
        }
      ]
    }
    

    The readingOrder field is updated with the order of the rows. You will need some sort of index like this to update in your table.

    Kevin

This discussion has been closed.