2010-12-03 2 views
0

У меня есть следующий код в ExtJS и при визуализации он дает мне ошибку в хроме являетсяСетка Rendering Проблема

Uncaught TypeError: Cannot read property 'id' of undefined 


/*! 
* Ext JS Library 3.3.0 
* Copyright(c) 2006-2010 Ext JS, Inc. 
* [email protected] 
* http://www.extjs.com/license 
*/ 
Ext.chart.Chart.CHART_URL = 'extjs/resources/charts.swf'; 


Ext.onReady(function(){ 
    function change(val){ 
     if(val > 0){ 
      return '<span style="color:green;">' + val + '</span>'; 
     }else if(val < 0){ 
      return '<span style="color:red;">' + val + '</span>'; 
     } 
     return val; 
    } 
    function pctChange(val){ 
     if(val > 0){ 
      return '<span style="color:green;">' + val + '%</span>'; 
     }else if(val < 0){ 
      return '<span style="color:red;">' + val + '%</span>'; 
     } 
     return val; 
    } 
    var url = { 
     local: 'grid-filter.json', // static data file 
     remote: 'grid-filter.php' 
    }; 
    var encode = false; 
    // configure whether filtering is performed locally or remotely (initially) 
    var local = false; 
    var store = new Ext.data.JsonStore({ 
     // store configs 
     autoDestroy: true, 
     url: (local ? url.local : url.remote), 
     remoteSort: false, 
     sortInfo: { 
      field: 'id', 
      direction: 'ASC' 
     }, 
     storeId: 'myStore', 

     // reader configs 
     idProperty: 'id', 
     root: 'data', 
     totalProperty: 'total', 
     fields: [{ 
      name: 'id' 
     }, { 
      name: 'p_name' 
     }, { 
      name: 'status', 
      type: 'string' 
     }, { 
      name: 'company', 
      type: 'string', 
     }] 
    }); 

    var createColModel = function (finish, start) { 
     var columns = [{ 
      dataIndex: 'id', 
      header: 'Id', 
      // instead of specifying filter config just specify filterable=true 
      // to use store's field's type property (if type property not 
      // explicitly specified in store config it will be 'auto' which 
      // GridFilters will assume to be 'StringFilter' 
      filterable: true 
      //,filter: {type: 'numeric'} 
     }, { 
      dataIndex: 'p_name', 
      header: 'Project', 
      id: 'company', 
      filter: { 
       type: 'string' 
       // specify disabled to disable the filter menu 
       //, disabled: true 
      } 
     }, { 
      dataIndex: 'status', 
      header: 'Status', 
      filter: { 
       type: 'string' // specify type here or in store fields config 
      } 
     }, { 
      dataIndex: 'company', 
      header: 'Company', 
      filter: { 
       type: 'string' 
       //options: ['small', 'medium', 'large', 'extra large'] 
       //,phpMode: true 
      } 
     }, { 
      dataIndex: 'visible', 
      header: 'Visible', 
      filter: { 
       //type: 'boolean' // specify type here or in store fields config 
      } 
     }]; 

     return new Ext.grid.ColumnModel({ 
      columns: columns.slice(start || 0, finish), 
      defaults: { 
       sortable: true 
      } 
     }); 
    }; 

    //------- END ------// 

    //create editor 

    // create the Grid 


    var grid = new Ext.grid.GridPanel({ 
     store: store, 
     plugins:[editor], 
     columns: [sm, 
      { 
     id:'company', 
     header: "Project", 
     width: 70, 
     sortable: true, 
     dataIndex: 'p_name', 
     editor: { 
      xtype: 'textfield', 
      allowBlank: false 
     }, 
     filter: { 
       type: 'string' 
       //options: ['small', 'medium', 'large', 'extra large'] 
       //,phpMode: true 
      } 
     }, 
     { 
      header: "Status", width: 75, sortable: true, dataIndex: 'status', 
      valueField: "name",displayField: "name", triggerAction: "all", 
      filter: { 
       type: 'string' 
       //options: ['small', 'medium', 'large', 'extra large'] 
       //,phpMode: true 
      }, 
      editor: { 
       xtype: 'combo', 
       allowBlank: false 
      }}, 
      {header: "Company", width: 175, sortable: true, renderer: change, dataIndex: 'company',filter: { 
       type: 'string' 
       //options: ['small', 'medium', 'large', 'extra large'] 
       //,phpMode: true 
      },editor: { 
       xtype: 'textfield', 
       allowBlank: false 

       },} 
     ], 
     /*------*/ 
     sm: sm, 
     /*------*/ 

     stripeRows: true, 
     autoExpandColumn: 'company', 
     height:200, 
     width:905, 
     frame:true, 
     title:'Sliding Pager', 
     plugins: [filters], 
     autoExpandColumn: 'company', 
     listeners: { 
      render: { 
       fn: function(){ 
        store.load({ 
         params: { 
          start: 0, 
          limit: 50 
         } 
        }); 
       } 
      } 
     }, 
     bbar: new Ext.PagingToolbar({ 
      pageSize: 10, 
      store: store, 
      displayInfo: true 
     }) 
    }); 
    var filters = new Ext.ux.grid.GridFilters({ 
     // encode and local configuration options defined previously for easier reuse 
     encode: encode, // json encode the filter query 
     local: local, // defaults to false (remote filtering) 
     filters: [{ 
      type: 'numeric', 
      dataIndex: 'id', 
       disabled: false 
     }, { 
      type: 'string', 
      dataIndex: 'company', 
      disabled: false 
     }, { 
      type: 'string', 
      dataIndex: 'p_name', 
       disabled: false 
     }, { 
      type: 'string', 
      dataIndex: 'status', 
       disabled: false 
     },] 
    }); 
    var sm = new Ext.grid.CheckboxSelectionModel(); 
    var editor = new Ext.ux.grid.RowEditor({ 
    // saveText: 'Update' 
    }); 
    grid.render('grid-example'); 
    store.load({params:{start:0, limit:10} }); 
    //--------------- END ------------// 
}); 

Мой HTML-код:

<form id="myform" name="myform"> 
<table> 
    <tr> 
     <td height="" valign="top" colspan="3"> 
      <div id="grid-example"> 
      </div> 
     </td> 
    </tr> 
</table> 
</form> 

Пожалуйста, посоветуйте, что это проблема?

ответ

0

Глядя на это быстро, я заметил, что у вас есть «id» с заглавной буквы «Id» в одном месте, но в нижнем регистре в каждом другом экземпляре. Я бы начал с того, что исправил это и попытался запустить его снова.

Если это не исправить, возможно, попробуйте использовать что-то другое, кроме «id»? В основном, я хотел сообщить вам о капитализации.

var columns = [{ 
     dataIndex: 'id', 
     header: 'Id', 
     // instead of specifying filter config just specify filterable=true 
     // to use store's field's type property (if type property not 
     // explicitly specified in store config it will be 'auto' which 
     // GridFilters will assume to be 'StringFilter' 
     filterable: true 
     //,filter: {type: 'numeric'} 
    } 
Смежные вопросы