ExtJS – how to add data to store and filter in combobox

  Kiến thức lập trình

I added combobox to my application:

  getParticipantsStore() {
      return Ext.create('Ext.data.Store', {
          fields: ['marketName'],
          data: [], // Początkowo puste, dane zostaną załadowane później
  });



const store = this.getStore();

this.add({
  xtype: 'combobox',
  fieldLabel: 'Filter by Market',
  store: store,
  displayField: 'marketName',
  valueField: 'marketName',
  queryMode: 'local',
  multiSelect: true,
  listeners: {
    select: this.onMarketSelect,
    scope: this,
  },
});

this.loadMarketData(store);

I would like to have a list of all marketName in this combobox and filter by the value entered. Each value selected I would like to save i.e. in combobox I can select several values.

However, I can’t load the data into the store at all, much less filter by it.

I download the data in such a way (data in the form:

data: {
    data: Array[Array(array containing cells one by one)],
    header: Array[Object]
}

  loadMarketData(store) {
    let dataProvider = this.getDataProvider()

    if (dataProvider) {
      dataProvider.subscription.Resubscribe()
    } else {
      dataProvider = createDataProvider()
      this.setDataProvider(dataProvider)
    }
    this.getDataProvider()
      .DoRequest({
        command: 'GetData',
        tableName: 'market',
      })
      .$.subscribe(
        /** @param {Message} message */
        message => {
          if (Array.isArray(message.data.data)) {
            const marketNames = message.data.data.map(item => ({
              marketName: item[3],
            }));
            store.loadData(marketNames);
          } else {
            Ext.Msg.alert('Error', 'Failed to load data.');
          }
        },
      )

  },

As you can see I am trying to load the data into the store by:
store.loadData(marketNames);
but nothing is displayed in my combobox

How to load data into store? How do I add a function that will return the text by which it filters and run a function that will ask for the data and update the store?

Thank you.

LEAVE A COMMENT