Get Datatable data in current reordered/sorted order?

Get Datatable data in current reordered/sorted order?

vikasspalav09@gmail.comvikasspalav09@gmail.com Posts: 4Questions: 1Answers: 0

I have a data table which has a functionality of row reorder and sorting. While saving the current status of the table i want to get data data in current reordered / sorted order.

I am using fnGetData() but its giving table data in original order at load.

Thanks.

Answers

  • vikasspalav09@gmail.comvikasspalav09@gmail.com Posts: 4Questions: 1Answers: 0

    Thanks @prats for your reply. But its not working .
    Its caching the data in app cache manager and maintains the state but not returning the reordered table data

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    Use the selector-modifier option that can be given to any of the selector methods. For example:

    table.rows( { order: 'applied' } ).data()
    

    to get the row data in the currently applied order.

    Allan

  • vikasspalav09@gmail.comvikasspalav09@gmail.com Posts: 4Questions: 1Answers: 0

    Thanks @allan for your reply.
    By setting selector-modifier option also i am still getting original order not the modified one.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Please show your code.

  • vikasspalav09@gmail.comvikasspalav09@gmail.com Posts: 4Questions: 1Answers: 0
    edited July 2017
    // Code to set datatable: 
    
    slFaqTable = $("#selectedFAQsDt")
              .on('init.dt', function (e, settings, json) {
                  reloadAvailableFAQs(json);
              })
              .dataTable({
                  deferRender: true,
                  responsive: true,
                  scrollY: "150px",
                  scrollCollapse: true,
                  pagingType: 'simple',
                  lengthMenu: [[5, 10, 25, 50], [5, 10, 25, 50]],
                  ajax: {
                      type: 'GET',
                      dataType: 'json',
                      cache: false,
                      async: true,
                      url: hostName + selectedFAQsUrl,
                      "dataSrc": "",
                      contentType: 'application/json;charset=utf-8',
                      "beforeSend": function (xhr) {
                          xhr.setRequestHeader('authorization', emagine.security.authorizationHeader());
                      }
                  },
                  'columns': [{
                          "title": "Order",
                          'visible': true,
                          'width':'50px',
                          "bSortable": true,
                          "bSearchable": true,
                          "mRender": function (data, type, full, meta) {
                              return meta.row + meta.settings._iDisplayStart + 1;
                          }
                      },
                      {
                          'data': 'question',
                          'className': 'dt-left dataTableCursor',
                          "title": "FAQ",
                          "bSortable": true,
                          "bSearchable": true,
                          "mRender": function (data, type, full) {
                              if (type === 'display') {
                                  return emagine.getShortLengthHtml(full.question, oemDisplayCharLength);
                              }
                              return data;
                          }
                      },
                  ],
              });
    
           slFaqTable.rowReordering();
    
    
    //Code to get datatable values after reordering:
    
    $.each($('#selectedFAQsDt').dataTable().fnGetData(), function (index, value) {
               faqList = faqList + ',' + value.faqdId;
           });
           faqList = faqList == '' ? '' : faqList.substring(1);
           return faqList;
    
  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    I don't actually see the selector modifier being used anywhere in that code. fnGetData is a legacy API method. The code I showed above will return the rows in the current order.

    Allan

  • DeanMillsDeanMills Posts: 5Questions: 1Answers: 0

    Tried table.rows( { order: 'applied' } ).data() but still showing the initiated row order

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    I believe this is regarding your other posts about getting table data in order after row reorder is complete. I answered you question in this thread.

    Kevin

This discussion has been closed.