1

i'm starter in jqgrid. i write this code for load jqgrid data and create some icon Button for show custom panel papup for insert and update.

  $(function () {
            $("#txtFullName").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "AutoCompleteHandler.ashx",
                        dataType: "json",
                        data: {
                            term: request.term,
                            Person: 1
                        },
                        contentType: "application/json",
                        converters: {
                            "json json": function (msg) {
                                return msg.hasOwnProperty('d') ? msg.d : msg;
                            }
                        },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.Label,
                                    value: item.Value,
                                    id: item.Id
                                }
                            }));
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 1,
                change: function (event, ui) { $("#PersonId").val(ui.item.id); }

            });

            var grid = $('#list');
            grid.jqGrid({
                url: 'jQGridHandler.ashx',
                editurl: 'jQGridHandler.ashx',
                postData: { ActionPage: 'SecurityUser', Action: 'Fill' },
                ajaxGridOptions: { cache: false },
                loadonce: true,
                direction: "rtl",
                pgtext: "صفحه {0} از {1}",
                datatype: 'json',
                height: 490,
                colNames: ['کد کاربری', 'شماره پرسنلی', 'مدیر؟', 'نام کاربری ', 'رمز عبور', 'قفل؟', 'تاریخ ایجاد', ],
                colModel: [
                        { name: 'USER_ID', width: 100, sortable: true, hidden: true },
                        { name: 'PERSON_ID', width: 200, sortable: true },
                        { name: 'USER_TYPE', width: 100, sortable: true, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", formatoptions: { disabled: false} },
                        { name: 'USER_NAME', width: 100, sortable: true },
                        { name: 'USER_PASSWORD', width: 100, sortable: true },
                        { name: 'USER_LOCK', width: 50, sortable: true, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", formatoptions: { disabled: false} },
                        { name: 'CREATE_DATE', width: 30, sortable: true, hidden: true },

                        ],
                gridview: true,
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#pager',
                sortname: 'USER_ID',
                viewrecords: true,
                sortorder: 'ASC',
                caption: 'درخواست ها......',
                rownumbers: true
            });
            grid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: true }, {}, {},
                { url: "JQGridHandler.ashx?ActionPage=SecurityUser&Action=Delete", reloadAfterSubmit: false }, { multipleSearch: true, overlay: false, width: 460 })
                .navButtonAdd("#pager", {
                    caption: "",
                    buttonicon: "ui-icon-plus",
                    onClickButton: function () {
                        $("#PersonId").val('');
                        $("#chkAdmin").attr("checked", 'false');
                        $("#txtUserName").val('');
                        $("#txtPassword").val('');
                        $("#chkActive").attr("checked", 'false');
                        $("#hdnUserId").val('');


                        $("#btnUpdate").css("display", 'none');
                        $("#btnAdd").css("display", 'inline');
                        $("#POPUP1").dialog({ width: 730 });
                    },
                    position: "first"

                })
                .navButtonAdd("#pager", {
                    caption: "",
                    buttonicon: "ui-icon ui-icon-pencil",
                    onClickButton: function () {
                        $("#PersonId").val('');
                        $("#chkAdmin").attr("checked", 'false');
                        $("#txtUserName").val('');
                        $("#txtPassword").val('');
                        $("#chkActive").attr("checked", 'false');
                        $("#hdnUserId").val('');



                        var myGrid = grid;
                        var selRowId = myGrid.jqGrid('getGridParam', 'selrow');

                        $("#PersonId").val(myGrid.jqGrid('getCell', selRowId, 'PERSON_ID'));
                        $("#chkAdmin").attr("checked", myGrid.jqGrid('getCell', selRowId, 'USER_TYPE'));
                        $("#txtUserName").val(myGrid.jqGrid('getCell', selRowId, 'USER_NAME'));
                        $("#txtPassword").val(myGrid.jqGrid('getCell', selRowId, 'USER_PASSWORD'));
                        $("#chkActive").attr("checked", myGrid.jqGrid('getCell', selRowId, 'USER_LOCK'));
                        $("#btnAdd").css("display", 'none');
                        $("#btnUpdate").css("display", 'inline');
                        $("#hdnUserId").val(myGrid.jqGrid('getCell', selRowId, 'USER_ID'));

                        $("#POPUP").dialog({ width: 400 });

                    },
                    position: "first"

                });


            function add() {
                $.ajax({
                    url: 'JQGridHandler.ashx',
                    contentType: "application/json; charset=utf-8",
                    data: { PERSON_ID: $("#PersonId").val(), USER_TYPE: $("#chkAdmin").is(":checked"),
                        USER_NAME: $("#txtUserName").val(), USER_PASSWORD: $("#txtPassword").val(),
                        USER_LOCK: $("#chkActive").is(":checked"), ActionPage: 'SecurityUser', Action: 'Insert'
                    },
                    dataType: "json",
                    success: function (data) {
                        $("#list").trigger("reloadGrid", [{ current: true}]);    ??????
                    }

                });
            }
            function update() {

                $.ajax({
                    url: 'JQGridHandler.ashx',
                    contentType: "application/json; charset=utf-8",
                    data: { USER_ID: $("#hdnUserId").val(), PERSON_ID: $("#PersonId").val(), USER_TYPE: $("#chkAdmin").is(":checked"),
                        USER_NAME: $("#txtUserName").val(), USER_PASSWORD: $("#txtPassword").val(),
                        USER_LOCK: $("#chkActive").is(":checked"), ActionPage: 'SecurityUser', Action: 'Update'
                    },
                    dataType: "json",
                    success: function (data) { }

                });
            }
            $("#btnAdd").click(function () {
                add();

             //$("#list").jqGrid("reloadGrid");

            });
            $("#btnUpdate").click(function () {
                update();
            });
        });

and html form For create jqGrid and popup panel

 <div>
        <table id="list">
        </table>
        <div id="pager">
        </div>

        <div id="POPUP" dir="rtl">
            <table width="100%" class="tbl">
                <tr>
                    <td>
                       FullName
                    </td>
                    <td>
                        <input type="text" id="txtFullName" />
                    </td>
                </tr>
                <tr>
                    <td>
                        PersonId
                    </td>
                    <td>
                        <input type="text" id="PersonId" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="checkbox" id="chkAdmin" />IsAdmin?
                    </td>
                </tr>
                <tr>
                    <td>
                       UserName
                    </td>
                    <td>
                        <input type="text" id="txtUserName" />
                    </td>
                </tr>
                <tr>
                    <td>
                       Password
                    </td>
                    <td>
                        <input type="password" id="txtPassword" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="checkbox" id="chkActive" checked="checked" />IsActive
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input id="btnAdd" type="button" value="Add" />&nbsp;&nbsp;
                        <input id="btnUpdate" type="button" value="Edit" />&nbsp;
                        <br />
                        <input id="hdnUserId" type="hidden" />
                    </td>
                </tr>
            </table>
        </div>
    </div>

i want when user click in btnAdd and record insert in database jqGrid data reload(I want refresh jqGrid data). but i get 2 errors

 Error: no element found
    Source File: http://localhost:1041/Clerance_New/JQGridHandler.ashx?PERSON_ID=1001&USER_TYPE=false&USER_NAME=tttt&USER_PASSWORD=tttt&USER_LOCK=true&ActionPage=SecurityUser&Action=Insert
    Line: 1

and
Error: uncaught exception: jqGrid - No such method: reloadGrid

and for reload in ?????? line not run server side code in handler, I do not know why.

please help me. thanks all

Pouya
  • 1,908
  • 17
  • 56
  • 78
  • Is there a problem with the code you posted? Or are you just trying to extend it? – Justin Ethier May 01 '12 at 14:12
  • @ Justin Ethier: in my code when user add data Gqgrid not reload, but i want to reload jqgrid after user inserted data. thanks – Pouya May 01 '12 at 16:26

1 Answers1

4

I am not sure why you wrote relatively complex code instead of usage standard form editing, but it should be sure some important reason.

The code

$("#list"). $("#list").jqGrid("reloadGrid");

is definitively wrong. The correct code you have commented for some reason

$("#list").trigger("reloadGrid", [{current: true}]);

Moreover it's important to place the call inside of success callback of the corresponding $.ajax request inside of add or update functions which you use.

UPDATED: I've seen now that you used loadonce: true option. It means that the data will be loaded from the server once. After the first loading the value of datatype will be changed to 'local'. The next reload of the grid will be done locally. If you need to reload the data one more time from the server you have to reset datatype to it's initial value ('json' in your case) and only then reload the grid. See the answer for details.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @MohsenBahrzadeh: Sorry, but the error message say me nothing. You should debug the code. Is `JQGridHandler.ashx` was correctly called by `.trigger("reloadGrid")`? Which place of client or server code is origin of the error message? – Oleg May 02 '12 at 06:01
  • @ oleg : in reload don't run handler code, i update code in question, please help me, thanks – Pouya May 03 '12 at 06:24
  • @ Oleg: thanks for help me. just i have another problem and i ask question from this address http://stackoverflow.com/questions/10404303/solution-for-design-this-forms-in-jqgrid Please see also, very thanks – Pouya May 03 '12 at 06:49
  • @MohsenBahrzadeh: I seen the question, but didn't understand it. You wrote about form in the question. First what is unclear: do you mean form editing or the grid in some "form mode"? If you mean the grid itself than it's unclear why dropdown boxes should be display in the grid. Do you want start inline editing of all rows directly after loading of the data? – Oleg May 03 '12 at 07:05
  • @ Oleg : i want first fill all Cost in jqgrid(no problm in this),Then user select one request in top dropDownList and click in search button i Want if Already user save for this request cost get for all cost and show in grid(I have this problem) and user update inline and click in button click(i dont have implement inline update). Do I need to ask that question with more details? thanks Mr.Oleg – Pouya May 03 '12 at 07:16
  • @MohsenBahrzadeh: I reread your question and comments many time. I can't understand almost nothing. First what you mean under "Cost"? Is it expenditure or price? Want is the subject of the Request? What you mean under CostType? Which type of Cost? The quotation from your question "Request For store all request and requestCost for store cost all request" is absolutely unclear. You spoke about 3 tables, then you wrote about one more CostRequest table. You shows boxes in "Amount" and "Remark" and dropdown in "Currency Unit". Why you want to start inline editing in *all rows* directly after load? – Oleg May 03 '12 at 08:17
  • @MohsenBahrzadeh: Probably you should modify the text of [the question](http://stackoverflow.com/questions/10404303/solution-for-design-this-forms-in-jqgrid) to describe more clear what you want. It you would write example in the table (like apples, bananas, ...) it will be more clear what kind of information you want to display and which kind of changes you want allows the user to do. – Oleg May 03 '12 at 08:20
  • @MohsenBahrzadeh: There are many variants how you can allow the user to start inline editing or rows: on double click on the row, on selection of the row, of selection and then clicking of the "edit" button in navigator bar (`inlineNav`), on clicking of the "edit" botton in the row (formatter: "actions"). In any way the grid can't been sorted during at least one row is in inline editing mode. – Oleg May 03 '12 at 08:29
  • @Oleg Thanks a lot, I'm trying different things and searching from last an hour but was unable to get the solution. Your response update regarding changing `loadonce` worked, bunch of thanks mate – Adil Apr 20 '16 at 05:52
  • 1
    @Bhaiya: You are welcome! I recommend you to use `fromServer: true` option of `reloadGrid`, which exist in [free jqGrid](https://github.com/free-jqgrid/jqGrid) fork which I develop. – Oleg Apr 20 '16 at 06:16