2010-11-23 149 views
0

我已经在一个mvc项目中安装了jQuery网格,并将它连接到jQuery UI。初始加载没问题,看到控制器中的操作调用,结果按预期显示。如果我点击任何头文件进行排序 - 没有任何反应,并且操作未在控制器中调用。我在萤火虫中没有任何错误 - 只是没有发生。jqGrid事件没有触发

我错过了什么?

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> 

回答

0

如果使用datatype: 'json',则服务器负责数据排序和分页。您当前的服务器代码(GetRateTypes)不这样做。例如,看看this旧的答案,它显示了如何实现排序和分页。

+0

感谢您的回复。我知道这个动作并没有进行任何排序,为了简单起见,它就是这样。我遇到的问题是排序事件没有回应到操作。点击列标题时,不会触发事件,因此控制器中的操作不会被调用。 – Chev 2010-11-24 04:44:28

0

可能它没有排序,因为jqGrid不知道如何排序。尝试为colModel属性中的每个列应用'sorttype'属性。 更靠近documentation

+0

感谢您的回复。我知道这个动作并没有进行任何排序,为了简单起见,它就是这样。我遇到的问题是排序事件没有回应到操作。点击列标题时,不会触发事件,因此控制器中的操作不会被调用。 – Chev 2010-11-24 05:01:42