ExtJS 4 - 网格中的数据不可见,并选择成功

时间:2014-06-24 09:48:38

标签: extjs4.2

商店

Ext.define('Console.store.SubjectMaterial.DetailFormStore', {
extend: 'Ext.data.Store',

model: 'Console.model.SubjectMaterial.DetailFormModel',

proxy: {
    actionMethods: 'POST',
    type: 'ajax',
    // api: {
    //     read: './modules/source/store/SubjectMaterial/selectDetailForm.php'
    // },
    url:'./modules/source/store/SubjectMaterial/selectDetailForm.php',

    reader: {
        type: 'json',
        root: 'result',
        // totalProperty : 'total'
    }
},

sorters: {
    direction: 'ASC',
    property: 'material_name'
},

remoteSort: true,
autoLoad: false
};

模型

Ext.define('Console.model.SubjectMaterial.DetailFormModel',{
extend:'Ext.data.Model',
fields:[
{
    name:'material_id',
    type:'string'
},{
    name:'material_name',
    type:'string'
},{
    name:'material_version',
    type:'string'
},{
    name:'material_author',
    type:'string'
},{
    name:'material_detail',
    type:'string'
}]
}

选择的php bytheway选择的数据是成功的

<?php
require_once 'C:/mobile_learning/config/config.php';
require_once 'C:/cps/service/utility/common/init.php';

$result = array();
// filters
$filters = isset($_POST['filter']) ? json_decode($_POST['filter']) : null;
$filterBy = isset($_POST['filter']) ? $filters[0]->property : null;
$value = isset($_POST['filter']) ? $filters[0]->value : null;
// sorters
$sort = isset($_POST['sort']) ? json_decode($_POST['sort']) : null;
$sortBy = isset($_POST['sort']) ? $sort[0]->property : null;
$direction = isset($_POST['sort']) ? $sort[0]->direction : 'ASC';

$table = SYS_DBNAME . '.' . MOBILE_LEARNING_TABLE_MATERIAL_STORE;
$table2 = SYS_DBNAME . '.' . MOBILE_LEARNING_TABLE_TEACHER_INFO;

$columns = "material_store.material_id,
        material_store.material_name,
        material_store.material_version,
        material_store.material_detail,
        teacher_info.teacher_name";

$onClause = "material_store.material_author=teacher_info.teacher_id";

$baseClause = "material_store.school_id='{$sysSession->corp_id}'";
$filterClause = "material_store.{$filterBy}='{$value}'";

$orderBy = "{$sortBy}" . ' ' . "{$direction}";
//修改
$sql['select']['material']['info'] = array(
'mysql'=>"SELECT {$columns} FROM {$table} AS material_store
        LEFT JOIN {$table2} AS teacher_info ON {$onClause}
        WHERE {$baseClause} AND {$filterClause}
        ORDER BY {$orderBy}",
'mssql'=>"SELECT {$columns} FROM {$table} AS material_store
        LEFT JOIN {$table2} AS teacher_info ON {$onClause}
        WHERE {$baseClause} AND {$filterClause}
        ORDER BY {$orderBy}",
'oci8'=>"SELECT {$columns} FROM {$table} AS material_store
        LEFT JOIN {$table2} AS teacher_info ON {$onClause}
        WHERE {$baseClause} AND {$filterClause}
        ORDER BY {$orderBy}"
);

$records = dbGetAll($sql['select']['material']['info'][SYS_DBTYPE]);

$result['total'] = count($records);
$result['result'] = $records;

echo json_encode($result);
?>

视图

Ext.define('Console.view.SubjectMaterial.FormDetailInsert',{
extend:'Ext.grid.Panel',
alias:['widget.sumaformdetailinsert'],
//
requires:[
    'Ext.ux.ProgressBarPager',
    'Ext.ux.form.SearchField'
],
//
plugins:[
{
    ptype:'rowexpander',
    rowBodyTpl:new Ext.XTemplate(
        '<table class="row-expander-table">',
            '<tbody>',
                '<tr>',
                    '<td><b>'+MSG['label_material_detail']+':</b> {material_detail:this.checkNull}'+'</td>',
                '</tr>',
            '</tbody>',
        '</table>',

        {
            checkNull:function(value) {
                if (value == null || value == '') {
                    return '&nbsp;';
                }
                return value;
            }
        }
    )
}],
selType: 'checkboxmodel',
selModel: {mode: 'MULTI'},
autoScroll: true,

initComponent:function()
{
    Ext.apply(this,
    {
        width:600,

        store:'SubjectMaterial.DetailFormStore',
        // store:Ext.create('SubjectMaterial.DetailFormStore'),

        columns:[
        {
            header:MSG['label_material_name'],
            dataIndex:'material_name',
            flex: 1
        },{
            header:MSG['label_material_version'],
            dataIndex:'material_version',
            flex: 1
        },{
            header:MSG['label_material_author'],
            dataIndex:'material_author',
            flex: 1
        }],

        bbar:[
        {
            text:MSG['universal_form_btn_cancel'],
            action:'form_btn_cancel'
        },{
            text:MSG['universal_form_btn_confirm'],
            action:'form_detail_insert_confirm'
        }]
    });
    this.callParent(arguments);
}
});

controll

Ext.define('Console.controller.SubjectMaterial',{
extend: 'Ext.app.Controller',
models: [
    'SubjectMaterial.MasterModel',
    'SubjectMaterial.DetailModel',
    'SubjectMaterial.DetailFormModel'
    //
    // ,''
],
stores: [
    'SubjectMaterial.MasterStore',
    'SubjectMaterial.DetailStore',
    'SubjectMaterial.DetailFormStore'
    //
    // ,''
],
views: [
    'SubjectMaterial.FormDetailInsert',
    'SubjectMaterial.ActionPanel',
    'SubjectMaterial.GridMaster',
    'SubjectMaterial.GridDetail',
    'SubjectMaterial.PanelMasterDetail',
    'SubjectMaterial.TabPanel'
],

init: function(){
    this.control({
        'sumagridmaster': {
            itemclick: this.masterItemClick,
            select: this.masterSelect
        },'sumagriddetail': {
            itemclick: this.detailItemClick,
            select: this.detailSelect
        },'sumagriddetail button[action=suma_detail_insert]': {
            click: this.detailInsert
        },'sumagriddetail button[action=suma_detail_delete]': {
            click: this.detailDelete
        },'sumaformdetailinsert button[action=form_btn_cancel]': {
            click: this.btnCancel
        },'sumaformdetailinsert button[action=form_detail_insert_confirm]': {
            click: this.detailInsertConfirm
        }
    });
},masterSelect: function(obj,record,index,eOpts) {
    var detailStore = this.getStore('SubjectMaterial.DetailStore');
    var detailFormStore = this.getStore('SubjectMaterial.DetailFormStore');

    detailStore.clearFilter(true);
    detailStore.filter('subject_id', record.get('subject_id'));
    detailStore.reload();
    //
    // console.log(detailFormStore.getCount());
    detailFormStore.clearFilter(true);
    // console.log(detailFormStore.getCount());
    detailFormStore.filter('department_id', record.get('school_department_id'));
    // console.log(detailFormStore.getCount());
    detailFormStore.reload();
    //
    // console.log(detailFormStore.getProxy());
    // console.log(detailFormStore.getCount());
}, ... }

就是这样。 选择的数据所有成功和正确。 我不知道为什么网格的数据无法显示。 请告诉我出了什么问题?

1 个答案:

答案 0 :(得分:0)

我必须解决我的问题。

问题在于我没有添加过滤器的值。

此代码 detailFormStore.filter(&#39; department_id&#39;,record.get(&#39; school_department_id&#39;));

如果你过滤了什么值,那么你最需要选择并添加到模型中。

像那样

Ext.define('Console.model.SubjectMaterial.DetailFormModel',{
extend:'Ext.data.Model',
fields:[
{
    name:'material_id',
    type:'string'
},{
    name:'material_name',
    type:'string'
},{
    name:'material_version',
    type:'string'
},{
    name:'material_author',
    type:'string'
},{
    name:'material_detail',
    type:'string'
},{  //this thing is after add
    //坑!
    name:'department_id',
    type:'string'
}]
});

那就是工作。