질문은 이미 here으로 질문되었지만 솔루션이 저에게 맞지 않습니다. 알파벳 순서 ("type": "natural")로 테이블을 정렬하고 싶지만 빈 셀을 밑줄 (desc와 asc)로 사용하고 싶습니다. 단지 노래와 가수에 정렬 | N° | Edit | Song | Singer | Url |
같은 테이블빈 셀을 무시하기 위해 정렬 (사전 순) : dataTables
$(document).ready(function() {
$('#classement').dataTable({
"aoColumns": [
null,
null,
{ "type" : "mystring" },
{ "type" : "mystring" },
null
]
});
});
:
jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= 1;
else if (y == "" || y == " ") retVal= -1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= -1;
else if (y == "" || y == " ") retVal= 1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
으로 :
나는 FBAS에 의해 주어진 이전 솔루션을 시도했다.emty 셀은 아래쪽에 있습니다 (예상대로). 그러나 정렬에는 논리가 없습니다 (알파벳순이 아니므로 dataTable의 다른 속성을 사용해야합니까?).
해결책이있는 사람이 있습니까?
편집 : 동적으로 줄을 추가하는 경우 정렬을 새로 고치는 방법은 무엇입니까?
$("#example").find('tbody')
.append($('<tr>')
.append($('<td>')
.text('Boro')
)
);
가 jsfiddle – codebased