No sorting after adding a row

No sorting after adding a row

suttersutter Posts: 3Questions: 0Answers: 0

i have a page with multiple tables. in each row is a button for copying a row. i get the data for the copied row by a ajax call (because of some validation etc.), which gives an array of objects. each object represents a table cell. the row is not inserted in the right position. it is allways appended to the end or the beginning of the table depending of the sort order. and i cannot figure out why?

can anybody help me with a hint?

my datatables setup is:


$(document).ready(function() { jQuery.fn.dataTable.Api.register( 'addRowAndDisplay()', function ( aData , pid ) { this.$('tr.added').removeClass('added'); var oAdded = this.row.add(aData); var iAdded = oAdded.index(); var nAdded = oAdded.node(); $(nAdded).addClass('added').attr('data-pid',pid); if (iAdded >= 0) { var page = Math.floor( iAdded / this.page.info().length ); this.page( page ).draw( false ); } else { this.page().draw(false); } return this; }); $.extend( $.fn.dataTable.defaults, { 'stateSave': true, 'stateDuration':0, "order": [[ 1, "asc" ]], 'bFilter': false, "pagingType": "full_numbers", "retrieve": true, 'bSort':true, 'destroy':true, "dom": '<"top"p<"clear">>rt<"bottom"il<"clear">>', 'bLengthChange':false, "language": {"url": "js/sys/DataTables/de_DE.txt"}, 'aoColumnDefs': [{'aTargets': ["noSort"],'bSortable':false}, {'aTargets': ['date'],'type':'de_datetime'}, {'aTargets': ['_all'], "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) { if (typeof sData == 'object') { $(nTd).addClass(sData.css).html(sData.dt); if (sData.title) $(nTd).attr('title',sData.title); if (sData.data) { for (var i in sData.data) { $(nTd).attr('data-'+i,sData.data[i]); } } } } } ], createdRow:function( row, data, dataIndex ) { if (typeof data == 'object') { for (var i in data) { if (data[i].css == 'prj_tool') { var tb = $(row.cells[i]).children('.toolBox'); var n = tb.children('span').size(); tb.css('width',25 * n); } } } }, fnDrawCallback: function(){ var wrapper = this.parent(); var rowsPerPage = this.fnSettings()._iDisplayLength; var rowsToShow = this.fnSettings().fnRecordsDisplay(); var minRowsPerPage = this.fnSettings().aLengthMenu[0][0]; if ( rowsToShow <= rowsPerPage || rowsPerPage == -1 ) { $('.dataTables_paginate, .dataTables_info', wrapper).css('visibility', 'hidden'); } else { $('.dataTables_paginate, .dataTables_info', wrapper).css('visibility', 'visible'); } if ( rowsToShow <= minRowsPerPage ) { $('.dataTables_length', wrapper).css('visibility', 'hidden'); } else { $('.dataTables_length', wrapper).css('visibility', 'visible'); } var $this = $(this); $this.find('td.edit').attr('id',function(e) { var $this = $(this); return 'c-'+$this.closest("tr").index()+'-'+$this.closest('td').index(); }); $this.find('td.edit').editable('jeditable.php', { tooltip : 'Klicken, um zu ändern ...', id : 'id', type: 'textarea', submit : 'OK', indicator : '<img src="gui/loading.gif">', submitdata : function () { var $this = $(this); var m = $this.data('m'); var pid = $this.closest('tr').data('pid'); var dt = $this.closest('.elInfo').data(); return {'o':dt.o,'e':dt.elid,'m':m,'pid':pid}; }, cssclass : 'prj' }); } }); var tblClasses = 'stripe row-border order-column hover compact'; var tbls = $('table.sortable') .addClass(tblClasses) .DataTable(); });

Replies

This discussion has been closed.