3

我正在为我的应用程序使用 Extjs 4.2 网格。在我的网格中有一个选项可以选择多行并删除它们(通过复选框)。但我只是选定的行没有返回任何值。

贝娄是我的代码..

################################################# #########################
Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', '../js/extjs_4_2/examples/ux/');
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.ux.grid.FiltersFeature',
    'Ext.toolbar.Paging',
    'Ext.ux.PreviewPlugin',
    'Ext.ModelManager',
    'Ext.tip.QuickTipManager',
    'Ext.selection.CheckboxModel'
]);

Ext.onReady(function(){
Ext.tip.QuickTipManager.init();

Ext.define('ForumThread', {
    extend: 'Ext.data.Model',
   fields: [

       {name: 'patient_name'},
       {name: 'referrer_provider'},
       {name: 'admit_date'},
       {name: 'added_date'},                  
               {name: 'billing_date'},
       {name: 'dob'},
               {name: 'loc_name'},
       {name: 'physician_name'},
       {name: 'imploded_diagnosis_name'},                  
               {name: 'imploded_procedure_name'},
       {name: 'imploded_optional_name'},
       {name: 'imploded_quick_list_name'},
       {name: 'med_record_no'},
               {name: 'message'}
            ],

    idProperty: 'bill_id'
});

var url = {
    remote: '../new_charges_json.php'
};
// configure whether filter query is encoded or not (initially)
var encode = false;
// configure whether filtering is performed locally or remotely (initially)
var local = false;

// create the Data Store
var store = Ext.create('Ext.data.Store', {
    pageSize: 10,
    model: 'ForumThread',
    remoteSort: true,
    proxy: {
        type: 'jsonp',
        url: (local ? url.local : url.remote),
        reader: {
            root: 'charges_details',
            totalProperty: 'total_count'
        },
        simpleSortMode: true
    },
    sorters: [{
        property: 'patient_name',
        direction: 'DESC'
    }]
});

    var filters = {
    ftype: 'filters',
    // 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 are most naturally placed in the column definition, but can also be
    // added here.
    filters: [{
        type: 'string',
        dataIndex: 'patient_name'
    }]
};

// use a factory method to reduce code while demonstrating
// that the GridFilter plugin may be configured with or without
// the filter types (the filters may be specified on the column model

var createColumns = function (finish, start) {

    var columns = [
        {
            menuDisabled: true,
            sortable: false,
            xtype: 'actioncolumn',
            width: 50,


            items: [{
                icon   : '../js/extjs_4_2/examples/shared/icons/fam/user_profile.png',  // Use a URL in the icon config
                tooltip: 'Patient Profile',
                renderer: renderTopic,
                handler: function(grid, rowIndex, colIndex) {
                    var rec = store.getAt(rowIndex);
                    //alert("Bill Id: " + rec.get('bill_id'));
                    //Ext.Msg.alert('Bill Info', rec.get('patient_name')+ ", Bill Id: " +rec.get('bill_id'));
                    window.location.href="../newdash/profile.php?bill_id="+rec.get('bill_id');
                }
            }, 
        ]
        },
        {
        dataIndex: 'patient_name',
        text: 'Patient Name',
        sortable: true,
        // 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: 'referrer_provider',
        text: 'Referring',
        sortable: true
        //flex: 1,
    }, {
        dataIndex: 'admit_date',
        text: 'Admit date',
    }, {
        dataIndex: 'added_date',
        text: 'Sign-on date'
    }, {
        dataIndex: 'billing_date',
        text: 'Date Of Service',
        filter: true,
        renderer: Ext.util.Format.dateRenderer('m/d/Y')
    }, {
        dataIndex: 'dob',
        text: 'DOB'
        // this column's filter is defined in the filters feature config
    },{
        dataIndex: 'loc_name',
        text: 'Location',
        sortable: true
    },{
        dataIndex: 'physician_name',
        text: 'Physician (BILLED)',
        sortable: true
    },{
        dataIndex: 'imploded_diagnosis_name',
        text: 'Diagnosis'
    },{
        dataIndex: 'imploded_procedure_name',
        text: 'Procedure'
    },{
        dataIndex: 'imploded_optional_name',
        text: 'OPT Template'
    },{
        dataIndex: 'imploded_quick_list_name',
        text: 'Quick List'
    },{
        dataIndex: 'med_record_no',
        text: 'Medical Record Number'
    },{
        dataIndex: 'message',
        text: 'TEXT or NOTES'
    }



    ];

    return columns.slice(start || 0, finish);
};


var pluginExpanded = true;


var selModel = Ext.create('Ext.selection.CheckboxModel', {

        columns: [
        {xtype : 'checkcolumn', text : 'Active', dataIndex : 'bill_id'}
        ],
    checkOnly: true,
    mode: 'multi',
    enableKeyNav: false,


    listeners: {
        selectionchange: function(sm, selections) {
            grid.down('#removeButton').setDisabled(selections.length === 0);
        }
    }
});

var grid = Ext.create('Ext.grid.Panel', {
    //width: 1024,
    height: 500,
    title: 'Charge Information',
    store: store,
    //disableSelection: true,
    loadMask: true,
    features: [filters],
    forceFit: true,
    viewConfig: {
        stripeRows: true,
        enableTextSelection: true
    },
    // grid columns
    colModel: createColumns(15),

    selModel: selModel,

    // inline buttons
    dockedItems: [
       {
        xtype: 'toolbar',
        items: [{
            itemId: 'removeButton',
            text:'Charge Batch',
            tooltip:'Charge Batch',
            disabled: false,
            enableToggle: true,
    toggleHandler: function() {  // Here goes the delete functionality
                alert(selModel.getCount());
                var selected = selModel.getView().getSelectionModel().getSelections();
                alert(selected.length);
                var selectedIds;
                if(selected.length>0) {
                    for(var i=0;i<selected.length;i++) {
                        if(i==0)
                        {
                                selectedIds = selected[i].get("bill_id");
                        }   
                        else
                        {
                                selectedIds = selectedIds + "," + selected[i].get("bill_id");
                        }
                    }
                }

                alert("Seleted Id's: "+selectedIds);return false;

            }









        }]
    }],



    // paging bar on the bottom
        bbar: Ext.create('Ext.PagingToolbar', {
        store: store,
        displayInfo: true,
        displayMsg: 'Displaying charges {0} - {1} of {2}',
        emptyMsg: "No charges to display"
    }),
    renderTo: 'charges-paging-grid'
});

store.loadPage(1);
});
#

它在所选行的警报对话框中给出数字,这里是 alert(selModel.getCount()); 但在此之后,它在下面的行中抛出了一个javascript错误“selModel.getView is not a function” var selected = selModel.getView().getSelectionModel().getSelections(); 我将其更改为 var selected = grid.getView().getSelectionModel().getSelections(); 仍然抛出相同类型的错误(grid.getView 不是函数)。

4

2 回答 2

4

试试这个

var selected = selModel.getSelection();

而不是这个

var selected = selModel.getSelectionModel().getSelections();
于 2013-09-03T11:43:37.717 回答
2

你已经有了选择模型,为什么还要让视图回到选择模型?这就像在做node.parentNode.childNodes[0].innerHTML

selModel.getSelection();足够了。还请务必阅读文档,那里没有列出 getView 方法Ext.selection.CheckboxModel,所以你只是编造了!

于 2013-09-03T11:26:06.373 回答