datatable - serverside search(column filtering) 문제.

boingboing·2022년 3월 22일
1
  • 현재 datatable 버전: 1.11.4
  • 기존에 기본제공되는 search input 을 serverside로 검색 할 때는 input 인자 값 받아서 django에서 필터링했다.

  • 이번에는 컬럼별로 필터링 해야 한다.

  • FixedHeader에서, column filtering을 해야 한다.

  • When displaying tables with a particularly large amount of data shown on each page,

  • it can be useful to have the table's header and / or footer
    fixed to the top or bottom of the scrolling window.

  • This lets your users quickly determine what each column refers to rather than needing to scroll back to the top of the table.

방법1

Individual column filtering

STEP 1

  • 우선은 search input을 테이블에 넣어 보자.
    $('#example tfoot th').each( function () {
        var title = $('#example thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

STEP 2

  • 검색 이벤트 바인딩
$( '#example tfoot input' ).on( 'keyup change clear', function () {
    //우선 이벤트까진 정상 발생한다.
    //debugger

    if ( test_table.search() !== this.value && this.value.length>0) {
        search_result = test_table.search( this.value );
        search_result.draw();
    }
} );
  • 굳이 datatable안의 콜백으로 안넣어줘도 제이쿼리 함수로 datatable과 별개로 주면 된다.

현상

-> 똑같은 검색기능을 적용해도, serverside로 하면 안됨. 클라이언트 사이드는 잘 된다.

  • 페이지 자체 문제인가 싶어서 해당 페이지에서 클라이언트방식으로 검색시도

update in 7.17
-> 중요) 서버사이드 렌더링 할 때 search().draw()로 하면, 클라이언트 사이드 렌더링 아님. 서버사이드로 col[search][val] attribute 포함해서, 1번 더 서버에 보냄.

서버단에서 filter() 등으로 직접 노가다를 안 할 뿐이지, serverside가 아닌게 아님...-ㅁ-

https://datatables.net/extensions/colreorder/examples/initialisation/col_filter.html
http://live.datatables.net/tobekuxu/1/edit

0개의 댓글