0

I have installed the jquery grid in an mvc project and hooked it up to the jquery ui. Initial load is fine and see the calls to the action in the controller and the results are displayed as expected. If I click on any of the headers to sort - nothing happens and the action is not called in the controller. I don't have any errors in firebug - just no event.

Am i missing something?

public ActionResult GetRateTypes(string sidx, string sord, int page, int rows)
        {
            int totalPages = 1; // we'll implement later
            int pageSize = rows;
            int totalRecords = 3; // implement later

            var jsonData = new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = new[]{
                    new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
                    new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
                    new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
                }
            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }


<script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery("#list").jqGrid({
            url: '/Configuration/GetRateTypes',
                datatype: 'json',
                mtype: 'GET',
                colNames: ['Code', 'Name', 'Rate'],
                colModel: [
          { name: 'Code', index: 'Code', width: 40, align: 'left' },
          { name: 'Name', index: 'Name', width: 40, align: 'left' },
          { name: 'Rate', index: 'Rate', width: 400, align: 'left'}],
                pager: jQuery('#pager'),
                rowNum: 1,
                rowList: [5, 10, 20, 50],
                sortname: 'Code',
                sortorder: "desc",
                viewrecords: true,
                imgpath: '/css/blitzer/',
                caption: 'Interest Rate Types'
            });
        }); 
    </script>
Samuel Goldenbaum
  • 18,391
  • 17
  • 66
  • 104

2 Answers2

0

Probably it doesn't sort since jqGrid don't know how to sort. Try to apply 'sorttype' property for each column in colModel property. Read closer the documentation

Genius
  • 1,784
  • 14
  • 12
  • Thanks for the reply. I know the action does not do any sorting and left it like that for simplicity. The problem I am having is that the sort event is not firing back to the action. When click on the column headers, not event is fired so the action in the controller is not called. – Samuel Goldenbaum Nov 24 '10 at 05:01
0

If you use datatype: 'json' then the server is responsible for the data sorting and paging. Your current server code (GetRateTypes) don't do this. Look this old answer for example which shows how the sorting and paging can be implemented.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for the reply. I know the action does not do any sorting and left it like that for simplicity. The problem I am having is that the sort event is not firing back to the action. When click on the column headers, not event is fired so the action in the controller is not called. – Samuel Goldenbaum Nov 24 '10 at 04:44
  • @Chev: If one clicks on the column headers the grid will be just reloaded and `GetRateTypes` will be called with another `sidx` and `sord` values. – Oleg Nov 24 '10 at 07:00
  • @Chev: Probably you also removed "for simplicity" some options which use used in jqGrid also? For example if you use `loadonce:true` then after the first leading the `datatype:'json'` will be changed to `datatype:'local'` and the action like sorting and paging will be done locally without any call of your server components. Verify that you post the code which you really use. On the other side the default setting `align: 'left'` you can remove from all `colModel` item and deprecated parameter `imgpath` should be also removed because it is not used by jqGrid. – Oleg Nov 24 '10 at 09:42
  • Seems I had some config issues and resovled it now – Samuel Goldenbaum Nov 25 '10 at 06:27