잡담소장소

[jQuery] bootstrap table sort 문제 본문

Study ;3

[jQuery] bootstrap table sort 문제

유부뽀 2018. 2. 19. 18:51

bootstrap-table 사용 시, sidePagination 값을 server로 둘 경우 sort 하지 않는다!

그래서 처음 생성 시 sortName, sortOrder를 줘도 의미가 없다-_-;

SQL에 order by 를 넣어서 반환받은 값을 돌려주도록 하자..





ajax로 데이터를 가져와서 넘겨주면 load 함수가 실행된다

BootstrapTable.prototype.load = function (data) {
        var fixedScroll = false;

        // #431: support pagination
        if (this.options.sidePagination === 'server') {
            this.options.totalRows = data.total;
            fixedScroll = data.fixedScroll;
            data = data[this.options.dataField];
        } else if (!$.isArray(data)) { // support fixedScroll
            fixedScroll = data.fixedScroll;
            data = data.data;
        }

        this.initData(data);
        this.initSearch();
        this.initPagination();
        this.initBody(fixedScroll);
    };

initData함수에서 sidePagination 값을 체크해서 initSort 실행 여부를 제어한다

return 을 지워도 되지만 서버에서 정렬된 데이터를 보내주면 문제 없다 

sortable을 사용한 client 제어가 필요하다면 풀어야할지도...(이 부분은 테스트하지 않음)

BootstrapTable.prototype.initData = function (data, type) {
        if (type === 'append') {
            this.data = this.data.concat(data);
        } else if (type === 'prepend') {
            this.data = [].concat(data).concat(this.data);
        } else {
            this.data = data || this.options.data;
        }

        // Fix #839 Records deleted when adding new row on filtered table
        if (type === 'append') {
            this.options.data = this.options.data.concat(data);
        } else if (type === 'prepend') {
            this.options.data = [].concat(data).concat(this.options.data);
        } else {
            this.options.data = this.data;
        }

        if (this.options.sidePagination === 'server') {
            return;
        }
        this.initSort();
    };


이거 찾으려고 삽질한거 생각하믄..ㅠㅠ 에휴

반응형
Comments