Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found a solution (although still open to hearing other ideas).</p> <p>First, you can call a store's load() function with a config object that will be passed to an operation. The API docs for Ext.data.Operation make it clear that one of the config options is for an array of Filter objects, so you can do this:</p> <pre><code>var idFilter = Ext.create('Ext.util.Filter', { property: 'id', value: '100,200,300' }); myStore.load({ filters: [ idFilter ] }); </code></pre> <p>This results in a request where the URL querystring contains <code>?filter=[{"property"%3Aid%2C"value"%3A100,200,300}]</code> (in other words, a URL-encoded version of <code>[{ property: 'id', value: '100,200,300'}]</code>).</p> <p>You can also just call <code>myStore.filter('id', '100,200,300')</code> without having called <code>.load()</code> first. Assuming you have remoteFilter=true in your store, this will make a request with the same query params shown agove.</p> <p><em>Sidenote</em>: you can change the keyword used for 'filter' by configuring the 'filterParam' config option for the proxy. For example, if filterParam=q, then the querystring shown above changes to: <code>?q=[{"property"%3Aid%2C"value"%3A100,200,300}]</code></p> <p><strong>Second</strong>, you can control "structure" of the filter in the querystring. In my case, I didn't want something like filter={JSON}, as shown above. I wanted a querystring that looked like this:<code>?id=100,200,300</code> For this I needed to extend a proxy and override the default getParams() function:</p> <pre><code>Ext.define('myapp.MyRestProxy', { extend: 'Ext.data.proxy.Rest', /** * Override the default getParams() function inherited from Ext.data.proxy.Server. * * Note that the object returned by this function will eventually be used by * Ext.data.Connection.setOptions() to include these parameters via URL * querystring (if the request is GET) or via HTTP POST body. In either case, * the object will be converted into one, big, URL-encoded querystring in * Ext.data.Connection.setOptions() by a call to Ext.Object.toQueryString. * * @param {Ext.data.Operation} operation * @return {Object} * where keys are request parameter names mapped to values */ getParams: function(operation) { // First call our parent's getParams() function to get a default array // of parameters (for more info see http://bit.ly/vq4OOl). var paramsArr = this.callParent(arguments), paramName, length; // If the operation has filters, we'll customize the params array before // returning it. if( operation.filters ) { // Delete whatever filter param the parent getParams() function made // so that it won't show up in the request querystring. delete paramsArr[this.filterParam]; // Iterate over array of Ext.util.Filter instances and add each // filter name/value pair to the array of request params. for (var i = 0; i &lt; operation.filters.length; i++) { queryParamName = operation.filters[i].property; // If one of the query parameter names (from the filter) conflicts // with an existing parameter name set by the default getParams() // function, throw an error; this is unacceptable and could cause // problems that would be hard to debug, otherwise. if( paramsArr[ queryParamName ] ) { throw new Error('The operation already has a parameter named "'+paramName+'"'); } paramsArr[ queryParamName ] = operation.filters[i].value; } } return paramsArr; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload