如何将存储的一部分加载到网格中

How to load a part of store into a grid

本文关键字:加载 网格 一部分 存储      更新时间:2023-09-26

Ext JS 5.1

我有一个学生管理系统,从1年级到4年级有4个班。所有班级各有4门课程。我把所有课程都调用到网格中,但我只想调用和学生有相同类的课程。(例如,我在四年级,所以我只能在网格上看到四年级的课程(

如果可能的话,我只想成为这样的代码的一部分:

    if (refs.txtClass.value === refs.lesClass.value){
       // load the grid that only equals txtClass.value
       // txtClass is Class No of a student, lesClass is Class No of grid
    }

学生课堂参考

items: [{
         xtype: 'label',
         flex: 1,
         reference: 'txtClass'
        }]

网格代码

items: [
{
    xtype: 'gridpanel',
    flex: 1,
    reference: 'courseList',
    itemId: 'courseList',
    store: 'CourseStore',
    columns: [
        {
            xtype: 'gridcolumn',
            reference: 'lesId',
            itemId: 'lesId',
            dataIndex: 'lesId',
            text: 'DERS KODU'
        },
        {
            xtype: 'gridcolumn',
            reference: 'lesClass',
            itemId: 'lesClass',
            dataIndex: 'lesClass',
            text: 'SINIF'
        },
        {
            xtype: 'gridcolumn',
            reference: 'lesName',
            itemId: 'lesName',
            width: 200,
            dataIndex: 'lesName',
            text: 'DERS ADI'
        },
        {
            xtype: 'gridcolumn',
            reference: 'lesCredit',
            itemId: 'lesCredit',
            dataIndex: 'lesCredit',
            text: 'DERS KREDİSİ'
        },
        {
            xtype: 'gridcolumn',
            reference: 'lesTeacher',
            itemId: 'lesTeacher',
            width: 600,
            dataIndex: 'lesTeacher',
            text: 'OKUTMAN'
        }
    ]
}]

如果您已经在本地加载了所有数据,那么您可以根据条件在存储中进行筛选。

filterBy(fn,[scope](
按函数筛选。将为此存储中的每个记录调用指定的函数。如果函数返回true,则包含Record,否则将过滤掉它。筛选存储时,访问存储数据的大多数方法将仅在筛选的记录集中工作。值得注意的例外是getById。

store.filterBy(function() 
{
if (refs.txtClass.value === refs.lesClass.value){
        return true;
    }
    else {
        return false;
    }
},this);

您还可以在商店中使用过滤器配置。

 filters: [
    function(item) {
        //condition here
    }
]
You can also loadData method of store to load some part of data in store :
    var arr = [],
    store = yourgrid.getStore();
    store.each(function(rec) {
    if (// condition to create the part of data want to be loaded)){
        arr.push(rec);
    }
    store.loadData(arr);     

您也可以使用slice方法来存储基于范围的一些数据store.loadData(oldstoreRecords.sice(开始,结束(;