Search code examples
extjsgridmatcher

Ext JS regex and getcmp


var grid = Ext.getCmp('grid');

var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");

Is there someone who can explain these lines of code to me?


Solution

  • Ext.getCmp is sort of a document.getElementById() of ExtJS.

    You create an element like:

    Ext.create('Ext.panel.Panel',{
        title: 'Foo',
        html: 'Bar',
        id: 'mytest',
        renderTo: document.body
     });
    

    then running Ext.getCmp('mytest') will return that panel instance so you can do things to it, for example:

    var panel = Ext.getCmp('mytest');
    test.setTitle('Hello');
    

    Creating a new RegExp has nothing to do with ExtJS, it's Javascript's standard way (one of) to create regular expressions (see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).

    Ext.String.escapeRegex will format a string in a way that is valid to be used in Regular expressions so Ext.String.escapeRegex(abs-$dxjksgg) will return abs\-\$dxjksgg