2012-05-24 2 views
4

ext 3.4 그리드 필터 플러그인을 사용하여 작동 가능한 정렬 가능한 그리드가 있습니다. true 값을 필터링하려면 활성 열을 기본값으로 설정하고 싶습니다. 비활성 레코드가 필요한 사용자는 필터를 제거 할 수 있습니다. 기본 필터 열과 값을 어떻게 지정합니까?Ext Grid Filter Default를 어떻게 설정합니까?

미리 감사드립니다.

colModel: new Ext.grid.ColumnModel({ 
    defaults: { 
     sortable: true 
     // How do I specify a default filter value 
     // 
     // Only show active records unless the user changes the filter... 
    }, 
    columns: [{ 
     dataIndex:'f_uid', 
     id:'f_uid', 
     header:'ID', 
     hidden:true 
    }, { 
     dataIndex:'f_name', 
     id:'f_name', 
     header:'Name', 
    }, { 
     xtype:'booleancolumn', 
     dataIndex:'f_active', 
     id:'f_active', 
     header:'Active', 
     filterable:true, 
     trueText:'Active', 
     falseText:'Inactive' 
    }] 
+1

대답은 Filter.js 소스 코드에 있었다 : 당신처럼 뭔가를 추가하려면 화면 구성 요소의

{ header: 'Filename', dataIndex: 'fileName', filter: { type: 'string', // filename that starts with current year value: Ext.Date.format(new Date(), 'Y'), active:true } }, 

: 그리고

그래서 열 항목이 같은입니다. 열 정의 내의 필터 객체를 사용하여 기본 비헤이비어를 구성 할 수 있습니다. 나는 아직 대답 할 수 없다. – RandomSilo

+0

필터 : {값 : 1, 활성 : true} – RandomSilo

답변

3

답변은 Filter.js 소스 코드에 있습니다. 열 정의 내의 필터 객체를 사용하여 기본 비헤이비어를 구성 할 수 있습니다. 그러므로 내가 공유하는 것이라고 생각

}, { 
     xtype:'booleancolumn', 
     dataIndex:'f_active', 
     id:'f_active', 
     header:'Active', 
     trueText:'Active', 
     falseText:'Inactive', 
     filterable:true, 
     filter: { 
      value:1, // 0 is false, 1 is true 
      active:true // turn on the filter 
     } 
} 
+4

위의 내용을 작성한 것처럼 필터를 설정했지만 페이지를로드 할 때는 필터가 활성화되어 있지 않습니다. 그리드를 새로 고친 후 필터를 활성화하고 결과를 표시합니다. 첫 번째 그리드로드에 대해 어떻게 활성화 시키는지 알고 있습니까? – efirat

4

나는이 오래된 질문 실현하지만 해결책을 찾기 위해 걸 렸어요.

1) 필터는 필터의 value 속성을 사용하여 설정할 수 있습니다.

filter: { 
      type: 'LIST', 
      value: ['VALUE TO FILTER'] 
     } 

2) 데이터를 처음 필터링하려면 저장소에서 filterBy() 메소드를 사용하십시오. 이것은 onRender 이벤트 핸들러에서 정의 될 수 있습니다.

this.getStore().load({ 
    scope:this, 
    callback: function() { 
     // filter the store 
     this.getStore().filterBy(function(record, id) { 
      // true will display the record, false will not 
      return record.data.DATA_TO_FILTER == 'VALUE TO FILTER '; 
     }); 
    } 
}); 
1

저도 같은 문제가 발생하고있다 나는 요한의 대답은 맞다 @, 난 그냥 같은 코드를 추가, 그리드 필터 - local.js를 들어, 샘플 http://dev.sencha.com/deploy/ext-4.0.0/examples/grid-filtering/grid-filter-local.html 작업을 할 수 있다는 것을 발견 :

원래의 코드 store.load() 이전
grid.getStore().load({ 
    scope:this, 
    callback: function() { 
     // filter the store 
     grid.getStore().filterBy(function(record, id) { 
      // true will display the record, false will not 
      return record.data.size === 'small'; 
     }); 
    } 
}); 

하고 store.load()을 닦아. 그러면 웹 페이지의 첫 번째로드시 크기가 '작음'인 레코드 만 표시됩니다. 건배!

0

필자는 열 정의에서 기본값을 설정할 수있는 범용 도우미 클래스를 만들었습니다. https://gist.github.com/Eccenux/ea7332159d5c54823ad7

원격 저장소와 정적 저장소 모두에서 작동해야합니다. 이것은 filterbar plugin에서도 작동합니다.

initComponent: function() { 
    this.callParent(); 

    // apply default filters from grid to store 
    var grid = this.down('grid'); 
    var defaultFilters = Ext.create('Ext.ux.grid.DefaultFilters'); 
    defaultFilters.apply(grid); 
}, 
관련 문제