Default sorting is not working

Default sorting is not working

ulicigabrielulicigabriel Posts: 1Questions: 1Answers: 0
edited November 2015 in Free community support

Hi,

So i create the table and after i call a function to populate all the rest of the columns of the table, and after everything is populated the sorting is not working, i tried even a custom sort function but the value return is the defaultContent.

How can i fix this?

Thanks.

P.S. Here is the code that creates the table.

 var tableData = [
    {
      "country_name": "Austria",
      "total": "7",
    },
    {
      "country_name": "Italy",
      "total": "7",
    },
  ];

  columnsArray.push({mDataProp: graph, orderable: false, className: 'select-checkbox', data: null, defaultContent: '-'});
  columnsArray.push({mDataProp: self.nameCol,      title: 'Name',          className: 'name', defaultContent: '-'});
  columnsArray.push({mDataProp: 'full_money',      title: 'Full money',    className: 'full_money', defaultContent: '-'});
  columnsArray.push({mDataProp: 'low_money',       title: 'Low money',     className: 'low_money', defaultContent: '-'});
  columnsArray.push({mDataProp: 'no_money',        title: 'No money',      className: 'no_money', defaultContent: '-'});
  columnsArray.push({mDataProp: 'avg_val',         title: 'Average value', className: 'avg_val', defaultContent: '-'});
  columnsArray.push({mDataProp: 'total_signup',    title: 'Signups value', className: 'total_signup', defaultContent: '-'});
  columnsArray.push({mDataProp: 'total_rebill',    title: 'Rebills value', className: 'total_rebill', defaultContent: '-'});
  columnsArray.push({mDataProp: 'total_money',     title: 'Total money',   className: 'total_money', defaultContent: '-'});
  columnsArray.push({mDataProp: 'total_canceled',  title: 'Canceled',      className: 'total_canceled', defaultContent: '-'});
  columnsArray.push({mDataProp: 'total',           title: 'Total signups', className: 'total', defaultContent: '-'});


  $('.subData')
     .on('init.dt', function(e, settings, json) { 
      // Populate the table only on the first body render
        populateTblSubscrition();
    })
    .DataTable( {
      'aaData': tableData,
      'aoColumns': columnsArray,
      'info': false,
      'paging': false,
      'searching': false,
      'responsive': true,
      'aaSorting': [],
      'fnCreatedRow': function( nRow, aData, iDataIndex ) {
        $(nRow).attr('data-index', iDataIndex);
      },
      'columnDefs': [{
         'targets': 0,
         'searchable': false,
         'orderable': false,
         'className': 'dt-body-center',
         'render': function (data, type, full, meta){
             // return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
         },
      }],
    });

Answers

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    Can you link to a page showing the issue - per the forum rules please.

    The above code should result in the initial table display being shown with the same order as what was given in the aaData option (data in the new options name).

    Allan

This discussion has been closed.