2012-01-24 64 views
0

我是ExtJS的新手,我試圖在ExTJS網格中包含過濾器,但我遇到了一個錯誤,如加載失敗的文件「feature.filters」。下面是我創建Grid的函數,我從另一個HTML頁面調用這個函數。ExtJS過濾器功能錯誤

function ExtJSGrid(tableId,headerInfo,data){ 

Ext.Loader.setConfig({enabled: true}); 
Ext.Loader.setPath('Ext.ux', 'http://vmxplambardi:19086/teamworks/script/extjs/examples/ux'); 
Ext.require([ 
    'Ext.grid.*', 
    'Ext.data.*', 
    'Ext.ux.grid.FiltersFeature', 
    'Ext.toolbar.Paging' 
]); 


var tableId=tableId+"-div"; 
var fields=[],columns=[],dataIndex='cell'; 
var filters = { 
     ftype: 'filters', 
     local:true, 
     filters: [{ 
      type: 'string', 
      dataIndex: 'cell1' 
     }, { 
      type: 'string', 
      dataIndex: 'cell2' 
     }, { 
      type: 'string', 
      dataIndex: 'cell3' 
     }] 
    }; 

document.getElementById(tableId).innerHTML=''; 
for(var i=1;i<=headerInfo.length;i++) 
{ 

var cellObj={},columnObj={}; 

cellObj.name=dataIndex+i; 

fields.push(cellObj); 

columnObj.text=headerInfo[i-1]; 

columnObj.dataIndex=dataIndex+i; 

columns.push(columnObj); 
} 

var store = Ext.create('Ext.data.ArrayStore', { 

     fields:fields, 

     data: data 

    }); 

var grid = Ext.create('Ext.grid.Panel', { 

     store: store, 
     columns:columns, 
    width:'100%', 
    forceFit:true, 
    features: [filters], 
     renderTo: tableId 

     }); 
} 

請讓我知道如果我失去了什麼?

回答

0

JavaScript沒有塊級作用域,因此for循環中定義的變量實際上定義在函數的頂部(已懸掛)並在循環中存活。所以你總是覆蓋變量。

0

我已經得到了它的工作是這樣的:

var filters = { 
    ftype: 'filters', 
    // encode and local configuration options defined previously for easier reuse 
    encode: false, // json encode the filter query 
    local: true, // defaults to false (remote filtering) 

    // Filters are most naturally placed in the column definition, but can also be 
    // added here. 
    filters: [ 
     { 
      type: 'boolean', 
      dataIndex: 'visible' //Just an example 
     } 
    ] 
}; 

var myFilterGrid = new Ext.create('Ext.ux.LiveSearchGridPanel', { 
    title: 'someTitle', 
    selType: 'cellmodel', 
    store: myStore, 
    columns:[ 
     { 
      header: "Column1", 
      width: 90, 
      sortable: true, 
      dataIndex: 'INDEX1', 
      filterable: true, //<--- 
      filter:{   //<--- 
       type:'string' 
      } 
     }, 
     .... 
     { 
      header: "Another Column", 
      width: 85, 
      sortable: true, 
      dataIndex: 'INDEX2' 
     }], 
    features: [filters] //<--- 
    }); 

而且一定要包括

'Ext.ux.grid.FiltersFeature' 

希望這有助於!