1

I using jqgrid filtertoolbar. I'm having some 4 select filter in that. When i tried to select one of the values in any select box i'm getting the following error.

Unable to get property 'stype' of undefined or null reference

Is there any general error or missing value that i have done anywhere in my code.

//Code:

Sample of colModel:

colModel:

 jQuery.ajax({
        url: 'ManageCandidateDetails.aspx/GetAllCandidateDetails',
        type: "POST",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            // debugger;
            genericResult = $.parseJSON(data.d);
            //  debugger;
            jQuery("#CandidateDetailsGrid").jqGrid({
                data: genericResult.candidateDetails,
                datatype: "local",
                // colNames: ['CandidateId', 'Email', 'Name'],
                //colModel: [{ name: 'CandidateId', index: 'CandidateId', width: 75}, { name: 'Email', index: 'Email', width: 75 }, { name: 'Name', index: 'Name', width: 100}],
                colNames: ['CandidateId', 'Name', 'Email', 'DOB', 'Gender', 'Qualification', 'Department', 'OtherQual', 'OtherDept', 'Exp(Years)', 'Exp(Months)', 'Mobile', 'Country', 'State', 'City', 'ZipCode', 'FilePath', 'Sel.Status', 'CreatedDate', 'ModifiedDate', 'ModifiedBy', 'Status', 'LastLoginTime'],
                colModel: [{ name: 'CandidateId', index: 'CandidateId', width: 75, editable: true },
                           { name: 'Name', index: 'Name', width: 100, editable: true },
                           { name: 'Email', index: 'Email', width: 75, editable: true },
                           { name: 'DOB', index: 'DOB', width: 50, editable: true, searchoptions: { dataInit: newDatePick }, editoptions: { dataInit: newDatePick} },
                           { name: 'Gender', index: 'Gender', width: 50, editable: true },
                           { name: 'Qualification', index: 'Qualification', width: 75, editable: true, stype: 'select', editoptions: { value: ":All;" + genericResult.qualification} },
                           { name: 'Department', index: 'Department', width: 75, editable: true, stype: 'select', editoptions: { value: ":All;" + genericResult.department} },
                           { name: 'OtherQual', index: 'OtherQual', width: 75, editable: true },
                           { name: 'OtherDept', index: 'OtherDept', width: 75, editable: true },
                           { name: 'ExperienceYears', index: 'ExperienceYears', width: 75, editable: true },
                           { name: 'ExperienceMonths', index: 'ExperienceMonths', width: 75, editable: true },
                           { name: 'Mobile', index: 'Mobile', width: 100, editable: true },
                           { name: 'Country', index: 'Country', width: 100, editable: true, stype: 'select', formatter: 'select', edittype: 'select',
                               searchoptions: {
                                   value: allCountries, stype: 'select'

                               },
                               editoptions: {
                                   value: allCountries,
                                   dataInit: removeTheOptionAll,
                                   dataEvents: [
                            { type: "change", fn: function (e) { changeStateSelect($(e.target).val(), e.target); } }
                        ]
                               }
                           },
                           { name: 'state', index: 'state', width: 100, formatter: "select", stype: "select",
                               editable: true, edittype: "select",
                               editoptions: { value: allStates, dataInit: removeTheOptionAll },
                               searchoptions: { value: allStates }
                           },
                           { name: 'City', index: 'City', width: 50, editable: true },
                           { name: 'ZipCode', index: 'ZipCode', width: 50, editable: true },
                           { name: 'FilePath', formatter: function () { return "<img src='../Images/error.png' alt='my image' />"; }, unformat: imageUnFormat, index: 'FilePath', width: 50 },
                           { name: 'SelectedStatus', index: 'SelectedStatus', width: 75, edittype: 'checkbox', formatter: 'checkbox', editable: true, editoptions: { value: "1:Yes;0:No" }, stype: 'select', searchoptions: { sopt: ['eq'], value: "All:All;1:Yes;0:No"} },
                           { name: 'CreatedDate', index: 'CreatedDate', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
                               searchoptions: { dataInit: datePick }, editoptions: { dataInit: datePick }
                           },
                           { name: 'ModifiedDate', index: 'ModifiedDate', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
                               searchoptions: { dataInit: datePick }, editoptions: { dataInit: datePick }
                           },
                           { name: 'Modifiedby', index: 'ModifiedBy', width: 75 },
                           { name: 'Status', index: 'Status', width: 50, edittype: 'checkbox', editable: true, stype: 'select', searchoptions: { value: "All:All;1:Yes;2:No"} },
                           { name: 'LastLoginTime', index: 'LastLoginTime', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
                               searchoptions: { dataInit: datePick, attr: { title: 'Select Date'} }, editoptions: { dataInit: datePick }
                           }],
                rowNum: 10,
                mtype: 'GET',
                loadonce: true,
                rowList: [10, 20, 30],
                pager: '#CandidateDetailsGridPager',
                sortname: 'CandidateId',
                viewrecords: true,
                caption: "Candidate Details",
                ignoreCase: true,
                gridview: true,
                rownumbers: true

            });

            jQuery("#CandidateDetailsGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });

            $('#CandidateDetailsGrid').jqGrid('navGrid', '#CandidateDetailsGridPager',
               {
                   edit: true,
                   add: true,
                   del: true,
                   search: true,
                   searchtext: "Search",
                   addtext: "Add",
                   edittext: "Edit",
                   deltext: "Delete"
               },
               { // edit option
                   beforeShowForm: function (form) {

                   }
               },
               { // add option

                   addcaption: 'Add Candidate Detail',
                   beforeShowForm: function (form) {
                       //debugger;
                       $("#myFormError").remove();
                       $('#tr_LastLoginTime', form).hide();
                       $('#tr_CandidateId', form).hide();
                       $('#tr_Modifiedby', form).hide();
                       $('#tr_ModifiedDate', form).hide();
                       $('#tr_CreatedDate', form).hide();
                   },
                   onclickSubmit: function (response, postData) {
                       debugger;
                       $("#FormError").text("");
                       $("<tr id='myFormError'><td colspan='2'><div style='background-color:green;color:white; font-weight:bold; width:100%;padding-left:5px;'>Success</div></td></tr>").insertAfter("#FormError");


                   }
               }
               );

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
        }
    });

    //Unformat the image during the edit.
    function imageUnFormat(cellvalue, options, cell) {
        return cellvalue
    }
A Coder
  • 3,039
  • 7
  • 58
  • 129
  • 1
    Which `datatype` you use? Do you use `loadonce: true`? If you use `datatype: "local"` or remote `datatype` (`"json"` or `"xml"`), but with `loadonce: true` then you **have to** use `index` the same as `name`. On the other side you use `name: 'Sel.Status', index: 'SelectedStatus'` which is wrong. You should include more full code. Do you have the demo which reproduce the error? In which line of `jquery.jqGrid.src.js` of jqGrid 4.6 you have the error? – Oleg Sep 12 '14 at 06:42
  • @Oleg: The issue is with the name and index as u said. The error is been fixed now. But the filter isn't working. I'll post the full code now. – A Coder Sep 12 '14 at 07:07
  • `loadonce: true` will be ignored if you use `datatype: "local"`. The line `genericResult = $.parseJSON(data.d)` shows indirectly on an error on your server side. You makes probably **unneeded additional conversion of JSON** of the object with data. ASP.NET makes the conversion for you already. You need just return `object` and not `string`. Another thing: I recommend you to *remove* all `index` property from `colModel`. I recommend additionally to use column `template` (see [here](http://stackoverflow.com/a/6047856/315935)). It can dramatically reduce the code and makes it more readable. – Oleg Sep 12 '14 at 07:19
  • You wrote "the filter isn't working". It gives almost no information. What exactly not work? By the way you can remove `colNames` if it contains only the same values like `name` properties of `colModel`. – Oleg Sep 12 '14 at 07:20
  • @Oleg: When i type the column value in the filter for which the value is in the grid it doesn't show me the filtered result. Just it shows blank grid(no results). – A Coder Sep 12 '14 at 09:12
  • You should provide **the demo** (for example in jsfiddle) with **test data** (2 rows for example). The demo should use `jquery.jqGrid.src.js`. You should provide the test case to reproduce the problem: what one should type exactly in which column and so on. – Oleg Sep 12 '14 at 09:38

0 Answers0