1

Free jqgrid reads remote json data using

  $.jgrid.useJSON = true;
  $.extend(true, $.jgrid.defaults, {
            mtype: 'GET',
            url: '@Html.Raw(Url.Action("Entity", "API",))'
    } );

search window is defined using

$.extend(true, $.jgrid.search, {
            multipleSearch: true,
            recreateFilter: true,
            closeAfterSearch: true,
            overlay: 0,
            recreateForm: true
        });

If search button is pressed, ugly filters query string parameter is created like

http://localhost:52216/admin/API/Entity/DoklstlG?search=true&nd=1448746804617&rows=20&page=1&sidx=customer&_sord=desc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Klient_nimi%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22a%22%7D%5D%7D

How to change that this url, especially filters clause in generated in OData format ? I read jqgrid OData plugin wiki article but havent found such possibility.

Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

0

I can't suggest you an ready to use solution, but I point you in the direction how you can implement the requirement.

First of all I would recommend you to read the answer? It shows how to use server side sorting and paging of OData. One need to use $top, $skip, $orderby and $inlinecount URI parameters which can be set inside of serializeGridData. One can implement filtering in the same way. One need to convert filters parameter, created by jqGrid, to the object and parse all the rules. One need generate the corresponding $filter parameter, which support OData (like here and here). It's important to understand that the common implementation is not so easy and it could depend on the exact version of OData implementation which you use.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • It looks like jqgrid OData plugin `parseFilterGroup` already impements OData filter creation. Since file upload in not supported in this plugin, its data edit method cannot used. How to use OData plugin only to retrieve json data using OData search filter? – Andrus Nov 29 '15 at 16:02
  • @Andrus: OK, I see that `prepareExpression` and `parseFilterGroup` already implements setting of `$filter`. Sorry, but I don't understand which relation have file upload to searching parameters? – Oleg Nov 29 '15 at 16:44
  • Plugin forces OData for edit and delete also. For example, line https://github.com/free-jqgrid/jqGrid/blob/master/plugins/grid.odata.js#L963 overwrites existing Edit url. I can modify plugin source code and comment out those places, is this best solution. Or how to allow plugin to upload files from form edit if `edittype: 'file'` ? In this OData edit and insert from plugin can also used. – Andrus Nov 29 '15 at 17:58
  • @Andrus: Do you know OData standard for URI (see [here](http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part2-url-conventions/odata-v4.0-errata02-os-part2-url-conventions-complete.html#_Toc406398071))? It requires to specify the id not as `/id`, but as `(id)` instead. Thus the plugin follow the requirement and generate the correct URL for edit/delete operations. Support of `edittype: 'file'`is out of the scope of the plugin. You can see the email and the GitHub account of [Mark Babayev](https://github.com/mirik123) in the comment at the beginning of OData plugin. – Oleg Nov 29 '15 at 18:18
  • Since file input is not supported, non OData urls should used for edit and insert WebAPI. Those parts of plugin needs commented out. OData format sends property names for every row. Native jagrid json format receives only values array. Using OData makes data size much bigger and parsing is probably slower. – Andrus Nov 29 '15 at 18:38
  • Why sample contains line https://github.com/free-jqgrid/jqGrid/blob/master/plugins/grid.odata.js#L114 and next line 115 ? Those lines should deleted – Andrus Nov 29 '15 at 20:03
  • @Andrus: Please hold the subject of discussion: "query data using OData in query string". **No editing of data. No editing of data of the `edittype: 'file'` or `edittype: 'image'`**. Don't place all your problems together. – Oleg Nov 29 '15 at 20:05
  • @Andrus: Post all suggestions of improvement of the code of OData plugin to the author. I personally find the plugin very good, but no code is perfect and it can be improved of cause. By the way, the line which you reference is inside of the comment. – Oleg Nov 29 '15 at 20:08