2014-09-24 3 views
0

내 머리를이 벽으로 부딪 치고 있습니다. 질문 제목에서 알 수 있듯이 MVC Razor View에는 JQuery Datatable이 있습니다. 하나의 열에는 영국식 날짜 (dd/mm/yyyy)가 표시되며 영국식 날짜를 기준으로이 열을 정렬하고 싶습니다.JQuery DataTable UK 날짜 정렬 작동하지 않음

나는 내 면도기보기

<script type="text/javascript" charset="utf-8"> 
     $(document).ready(function() { 

      jQuery.extend(jQuery.fn.dataTableExt.oSort, { 
       "date-uk-pre": function (a) { 
        var ukDatea = a.split('/'); 
        return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1; 
       }, 

       "date-uk-asc": function (a, b) { 
        return ((a < b) ? -1 : ((a > b) ? 1 : 0)); 
       }, 

       "date-uk-desc": function (a, b) { 
        return ((a < b) ? 1 : ((a > b) ? -1 : 0)); 
       } 
      }); 


      $('#example').dataTable({ 
       stateSave: true, 
       "aoColumnDefs" : [ 
         {"aTargets" : [1] , "sType" : "uk_date"} 
        ] 
      }); 


     }); 
</script> 

<table cellpadding="0" cellspacing="0" border="1" class="cdates" id="example"> 
    <thead> 
    <tr> 
     <th>Name</th> 
     <th>Date</th>  
     <th>Status</th> 
     <th>Applicants</th> 
    </tr> 
    </thead> 
    <tbody> 
     @foreach (var cd in Model) 
     { 
      <tr> 
      <td><strong>@cd.CourseName</strong></td> 
      <td>@cd.CourseDate</td> 
      <td>@cd.CourseStatus</td> 
      <td>@Html.ActionLink("View Applicants", "CDApps", "Portfolio", new { @id = @cd.CourseDateID, @[email protected] }, null)</td> 
      </tr>    
     } 
    </tbody> 
</table> 

하지만 여전히 내 날짜 정렬이 작동하지 않는 내에서 다음 있습니다. 스택 오버플로에 대한 다른 비슷한 질문을 살펴 봤지만 여전히 작동하지 않습니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까?

도움 주셔서 감사합니다.

답변

4

이 시도 : 당신이 "date-uk-pre", "date-uk-asc"

$('#example').dataTable({ 
     stateSave: true, 
     "aoColumnDefs" : [ 
      {"aTargets" : [1], "sType" : "date-uk"} 
     ] 
    }); 

"date-uk-desc"를 사용하여 정렬 기능과 같이 date-ukuk_date에서 sType 값을 대체 그리고 당신의 날짜 열 시간이 날짜 값에 포함했다,이에 대한 문제를 일으키는 정렬.

정렬 기능의 변경)은 시간 요소 Demo

2

"date-uk-pre": function (a) { 
      var ukDatea = a.split('/'); 
      var yearWithoutTimeValue = ukDatea[2].split(" ")[0]; 
      return (yearWithoutTimeValue + ukDatea[1] + ukDatea[0]) * 1; 
    }, 

제외

같은 테이블 열 값으로부터 시간을 제거하기 위해 두 용액

1) 확인 아래있다

<tr> 
    <td><strong>Electroconvulsive Therapy (ECT) (3 days)</strong></td> 
    <td>01/05/2014</td> 
    <td></td> 
    <td><a href="/Portfolio/CDApps/15454?CourseID=51">View Applicants</a></td> 
</tr> 

DEMO

+0

감사하지만 작동하지 않았습니다. 그것은 당신의 대답으로 모든 컬럼에서 실제로 정렬을 제거했습니다. – tgriffiths

+0

다른 답변을 시도했는데 정렬이 다시 돌아 왔지만 날짜 열은 여전히 ​​올바르게 정렬되지 않았습니다. 다른 제안? – tgriffiths

+0

내 업데이트 된 답변보기 –

관련 문제