开发者

What do I do to fix jqGrid throwing an error when (multi)selecting a row: 'className' is null or not an object?

开发者 https://www.devze.com 2023-02-28 15:46 出处:网络
I had selecting rows working fine. I then went and refactored my code to use OLN and added some defaults to my grid.

I had selecting rows working fine. I then went and refactored my code to use OLN and added some defaults to my grid.

Here is the default block of code:

var Grid = {  
SiteMaster: {
    setDefaults: function () {
        $.jgrid.defaults = $.extend($.jgrid.defaults, {
            datatype: 'json', 
            height: "100%",
            loadui: 'block',
            images: "/images/",
            jsonReader: {
                root: "Rows",
                page: "Page",
                total: "Total",
                records: "Records",
                repeatitems: false,
                userdata: "UserData",
                id: "Id"
            },
            loadui: "block",
            mtype: 'GET',
            autowidth: true,
            rowNum: 10,
            rowList: [10, 20],
            viewrecords: true
        });
    }
  }
};

and here is开发者_如何转开发 the actual grid code:

setupGrid: function (grid, pager) {
            disableControls();
            grid.jqGrid({
                colNames: ['Description', 'Ship Date', 'Memo'],
                colModel: [
                    { name: 'Description', index: 'Description', width: 400, align: 'left' },
                    { name: 'ShipDateDisplay', index: 'ShipDateDisplay', width: 100, align: 'left' },
                    { name: 'Memo', index: 'Memo', width: 200, align: 'left'}],
                pager: pager,
                url: gridurl,
                pager: pager,
                multiselect: true,
                multiboxonly: true,
                loadComplete: enableControls
            });

            initGridSearch();
        }

Here are my script references, too:

<script src="/CommonWeb/js/common.js" type="text/javascript"></script>
<script src="/CommonWeb/js/jquery.js" type="text/javascript"></script>
<script src="/CommonWeb/js/jquery.ui.js" type="text/javascript"></script>
<script src="/CommonWeb/js/jquery.blockUI.js" type="text/javascript"></script>
<script src="/CommonWeb/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/CommonWeb/js/jquery.jqGrid.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/grid.addons.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/grid.postext.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/grid.setcolumns.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/jquery.contextmenu.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/jquery.searchFilter.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/jquery.tablednd.js" type="text/javascript"></script>    
<script src="/CommonWeb/js/ui.multiselect.js" type="text/javascript"></script>    
<script src="@Url.Content("~/Content/js/Global.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/Grid.js")" type="text/javascript"></script>

Since the refactor, everytime I click on a row or select it via the check box controls, I get the javascript error 'className' is null or not an object. Any ideas? Thanks in advance.


Turns out I wasn't sending a unique identifier down with the data. This data was coming from a legacy table with no key on it. Once I slapped an identity field on it and generated an Id, everything started working again.


You posted not enough code to reproduce the problem. Which version of jqGrid you use?

The code of setDefaults where you try to set some defaults in $.jgrid.defaults seems incorrect for me. You should not assign the results of $.extend($.jgrid.defaults, {...}) to $.jgrid.defaults. The correct will be just call $.extend.

What is images: "/images/" parameter? You don't need define loadui: 'block' twice (second time as loadui: "block").

Inserting of jquery.jqGrid.js or inserting of grid.locale-en.js before it seems me wrong. I recommend you to look inside of jquery.jqGrid.js. Version 4.0 of jqGrid include jquery.jqGrid.src.js which is probably better to use.

Why you inserted so much modules? Do you use it? For example inserting of old jquery.searchFilter.js can overwrite new searching module grid.filter.js of jqGrid.

You should remove default value align: 'left' from the colModel.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号