I am retrieving some values from database like this:

var data = new Ext.create('Ext.data.Store',{
                                fields: [

                                        {name:'code',mapping: 'CODE'},{name:'code_company',mapping: 'COD_COMP'}, 
                                        {name:'descriptionCompany',mapping: 'DESC_COMP'}, {name:'group',mapping: 'GRP_GRP'},                                        

                                autoLoad: false,
                                remoteSort: true,
                                proxy: {               
                                    type: 'ajax',
                                    url: 'index.php?Control=GeneralData&Accion=companyData', // this is the Store Procedure from I am getting the data



I am getting this from database:

   1        1       1         APPLE
   1        1       2       MICROSOFT
   1        1       3          HP
   1        2       1        SAMSUNG
   1        2       2         NOKIA
   1        2       3         BLUE

so far everything is good. My problem come along when I am trying to get an specific record from that response.

I mean, I was trying to get the description (NOKIA) from that response like this:

var record = data.findRecord('code_company', 2);

The output from that code is "MICROSOFT" and not NOKIA as I wanted but I already know why is that happening. I need to be more expecific in my searching but that is what I donĀ“t know how to do.

I set 2 comboboxes in a form from where I am getting the group and the code chosen from the user. I save those values in 2 variables.

Now what I need is a piece of code that allow me to find a record based on the group and code chosen by the user.

for example if the user chose group 1 and code 2, I want to be able to display any record inside those parameters

1 Answers

Matheus Hatje On Best Solutions

You can use QueryBy that is used with a filtering function so you can get all records that match this function.

var records = store.queryBy(function(record, id) {
    return (record.get('code_company') == 2 &&
        record.get('code') == 2);

Then you can get each record doing a for each

 console.log('Company Name', record.get('descriptionCompany'));