简体   繁体   English

免费jqGrid-行未输入编辑

[英]Free jqGrid - Row not entering edit

I am using Free jqGrid 4.13.0 for a small project and i cant seem to make the rows to enter edit mode from both the action buttons and inlineNav edit button. 我正在为一个小项目使用Free jqGrid 4.13.0,我似乎无法使行从操作按钮和inlineNav编辑按钮进入编辑模式。

The rows get added by the "add" button but they dont enter editing mode. 这些行通过“添加”按钮添加,但是它们不进入编辑模式。 Trying to enter editing mode by using any of the buttons doesnt work either. 尝试通过使用任何按钮进入编辑模式都不起作用。

Could it be the order of the css/js files in witch they are entered in the html? 难道是在HTML中输入css / js文件的顺序? Am i missing a js file? 我是否缺少js文件?

I currently have 2 grids that are pretty much the same and neither of them works. 我目前有2个几乎相同的网格,但它们都不起作用。

<link rel="stylesheet" type="text/css" href="jqueryUI/jquery-ui.css"></link>
<link rel="stylesheet" type="text/css" href="jqueryUI/jquery-ui.min.css"></link>
<link rel="stylesheet" type="text/css" href="jqueryUI/jquery-ui.theme.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="jqueryGrid/css/ui.jqgrid.css"></link>
<link rel='stylesheet' href='css/bootstrap.css'></link>
<link rel="stylesheet" type="text/css"  href="css/cascade.css" />

<script src="jquery/jquery-1.12.1.min.js" type="text/javascript"></script>
<script src="jqueryUI/jquery-ui.min.js" type="text/javascript"></script>
<script src="jqueryGrid/js/i18n/grid.locale-en.js" type="text/javascript">  </script>
<script src="jqueryGrid/js/jquery.jqgrid.min.js" type="text/javascript">     </script>

<script src="customerGrid.js" type="text/javascript" ></script>
<script src="customerOrderGrid.js" type="text/javascript" ></script>

//// customerGrid.js file: //// customerGrid.js文件:

$(function() {
    var grid = $("#customersGrid");
    grid.jqGrid({
         url: "/LicentaREST/rest/customers/getCustomersGrid",
         mtype: "POST",
         datatype: "json",
        ajaxGridOptions: {contentType: 'application/json; charset=utf-8'},
        serializeGridData: function (postData) {
            if (postData.searchField === undefined) postData.searchField = null;
            if (postData.searchString === undefined) postData.searchString = null;
            if (postData.searchOper === undefined) postData.searchOper = null;
            return JSON.stringify(postData);
        }
        },
        colModel: [
            {name: 'ID', index: 'id', width: 55, hidden: true},
            {name: 'Name', index: 'name', width: 80, align: 'right', search: false},
            {name: 'Phone', index: 'phone', width: 90},
            {name: 'Address', index: 'address', width: 80, align: 'right', search: false},
            {name: 'Client Since', index: 'clientSince', width: 80, align: 'right', search: false},
            {name: 'Total Orders', index: 'totalOrders', width: 80, align: 'right', search: false},
            {name: 'Total Ammount Orders', index: 'totalAmmountOrders', width: 80, align: 'right', search: false},
            {name: 'Canceled Orders', index: 'canceledOrders', width: 80, align: 'right', search: false},
            {name: 'Black Listed Status', index: 'blackListed', width: 80, align: 'right', search: false},

        ],
        ondblClickRow: function (rowid) {
            $.ajax({
                type: "POST",
                url: "/LicentaREST/rest/getCustomerOrders",
                data: JSON.stringify(rowid),
                success: function (response) {
                    if (response.errorCode == 0) {
                        customersOrdersGrid.jqGrid('clearGridData').jqGrid('setGridParam', 'data', response.data);
                    }
                    else {
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(textStatus, errorThrown);
                }
            });
        },
        pager: "#customersPager",
        rowNum: 15,
        rowList: [15,50, 100, 250,500],
        rownumbers: true,
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        caption: 'Customers',
        height: "330",
        autowidth: true

    });
    grid.jqGrid('inlineNav', '#customersPager',
        {
            add: true,
            edit: false,
            save: false,
            cancel: false,
            addicon: 'ui-icon-plus',
            addtext: 'Add',
            addedrow: 'last'
    });
});

First of all I strictly recommend to use the latest free jqGrid version, which is published. 首先,我严格建议使用发布的最新免费jqGrid版本。 It's currently 4.13.2. 当前是4.13.2。 It contains some small bug fixes existing in version 4.13.0. 它包含4.13.0版中现有的一些小错误修复。 All the fixes have no relation to your problem. 所有修复程序都与您的问题无关。

I see the following problems in your code: 我在您的代码中看到以下问题:

  • The main problem is missing editable: true property in the columns of the grid which should be editable by the user. 主要问题是缺少editable: true网格列中的editable: true属性,用户应该可以对其进行编辑。
  • I recommend you to remove unneeded hidden id column and to use cmTemplate: { editable: true } option of jqGrid to set editable: true property in all columns of the grid. 我建议您删除不需要的隐藏id列,并使用cmTemplate: { editable: true }选项在网格的所有列中设置editable: true属性。 If you use some other properties in te most columns of jqGrid, like width: 80, align: 'right', search: false then it would be better to move the values in cmTemplate : cmTemplate: { editable: true, autoResizable: true, width: 80, align: 'right', search: false} , which specifies default values of the properties of colModel . 如果您在jqGrid的大多数列中使用其他一些属性,例如width: 80, align: 'right', search: false那么最好将这些值移动到cmTemplatecmTemplate: { editable: true, autoResizable: true, width: 80, align: 'right', search: false} ,它指定colModel属性的默认值。 You should skip specifying of the properties in colModel and overwrite the properties in other columns. 您应该跳过在colModel指定属性,而覆盖其他列中的属性。 For example you should continue to specify width: 90 in phone column. 例如,您应该继续在phone栏中指定width: 90
  • The properties of colModel seems be wrong. colModel的属性似乎是错误的。 You don't included any test data returned from the server (from url: "/LicentaREST/rest/customers/getCustomersGrid" ), but it seems that you mix the meaning of name , index and label properties of colModel . 您没有包括从服务器返回的任何测试数据(来自url: "/LicentaREST/rest/customers/getCustomersGrid" ),但是似乎您混合了colModelnameindexlabel属性的含义。 The name is like id of the column. name类似于列的ID。 It can't have spaces. 它不能有空格。 The values like name: 'Black Listed Status' are definitively wrong. name: 'Black Listed Status'这样的值肯定是错误的。 You mean probably label: 'Black Listed Status' . 您的意思可能是label: 'Black Listed Status' The values which you used for index property should be probably the values of name property. 您用于index属性的值可能应该是name属性的值。 It's strictly recommended to avoid specifying any index property at all if it's really required. 严格建议完全避免指定任何index属性(如果确实需要)。 Thus name: 'Black Listed Status', index: 'blackListed' for example should probably be changed to label: 'Black Listed Status', name: 'blackListed' like all other columns of jqGrid. 因此label: 'Black Listed Status', name: 'blackListed'label: 'Black Listed Status', name: 'blackListed'所有其他列一样label: 'Black Listed Status', name: 'blackListed' name: 'Black Listed Status', index: 'blackListed'可能应该更改为label: 'Black Listed Status', name: 'blackListed'
  • It's recommended to use pager: true instead of pager: "#customersPager" and to skip '#customersPager' parameter from inlineNav . 建议使用pager: true而不是pager: "#customersPager"并从inlineNav跳过'#customersPager'参数。 You can remove unneeded <div id="customersPager"></div> from HTML markup of the page and simplify code a little. 您可以从页面的HTML标记中删除不需要的<div id="customersPager"></div> ,并稍微简化代码。
  • I recommend to consider to remove height: "330" (correct would be height: 330 ) to use default height: "auto" . 我建议考虑删除height: "330" (正确的是height: 330 )以使用默认的height: "auto" The rowNum value will define the height of the grid in the case. rowNum值将定义案例中网格的高度。 The default setting height: "auto" is the best choice not in all scenarios, but in the most one. 默认设置height: "auto"不是在所有情况下的最佳选择,而是在大多数情况下的最佳选择。
  • You should review the CSS and JS files which you includes on the page. 您应该查看页面上包括的CSS和JS文件。 Including of jquery-ui.css , jquery-ui.min.css and jquery-ui.theme.css is wrong. 包括jquery-ui.cssjquery-ui.min.cssjquery-ui.theme.css是错误的。 It's enough to include just jquery-ui.min.css . 仅包含jquery-ui.min.css就足够了。 Instead of including ui.jqgrid.css you can include ui.jqgrid.min.css . 除了包含ui.jqgrid.css您还可以包含ui.jqgrid.min.css You should remove grid.locale-en.js because the file jquery.jqgrid.min.js contains already all the settings for en-US from grid.locale-en.js . 您应该删除grid.locale-en.js因为文件jquery.jqgrid.min.js已经包含了grid.locale-en.js en-US所有设置。
  • It's recommended to include Font Awesome 4.x CSS on the page and to add iconSet: "fontAwesome" option. 建议在页面上包括Font Awesome 4.x CSS并添加iconSet: "fontAwesome"选项。 It improves the look of icons displayed in the grid. 它改善了网格中显示的图标的外观。 You should remove addicon: 'ui-icon-plus' option from the call of inlineNav . 您应该删除addicon: 'ui-icon-plus'从看涨期权inlineNav It's default value in case of usage default jQuery UI icons and the value will be wrong if you would use Font Awesome icons. 如果使用默认的jQuery UI图标,则为默认值;如果使用Font Awesome图标,则该值为错误。 The call of inlineNav can be reduced to grid.jqGrid('inlineNav', {edit: false, save: false, cancel: false, addtext: 'Add', addParams: { position: 'last' }} inlineNav的调用可以减少为grid.jqGrid('inlineNav', {edit: false, save: false, cancel: false, addtext: 'Add', addParams: { position: 'last' }}
  • The variable customersOrdersGrid , which you use in ondblClickRow seems to be undefined. 您在ondblClickRow使用的变量customersOrdersGrid似乎未定义。 I'd recommend you to include "use strict"; 我建议您包括"use strict"; as the first statement of $(function() {...}); 作为$(function() {...});的第一条语句$(function() {...}); function to find easier such kind of error. 函数查找此类错误更容易。
  • You don't posted any information about the total number of rows, which could be returned on the server. 您没有发布有关总行数的任何信息,这些信息可以在服务器上返回。 I recommend you to use loadonce: true option and return all data at once if the total number of rows is not large enough. 我建议您使用loadonce: true选项,如果总行数不够大,请立即返回所有数据 For example less as 1000 or less as 10000. The demo can be used to test the performance of local paging, sorting and filtering of the grid with 4000 rows, 13 columns and 20 rows per page. 例如,小于1000或小于10000。 该演示可用于测试每页4000行,13列和20行的网格的本地分页,排序和筛选的性能。 Another demo uses even 40000 rows and it works very quickly too if you would use modern web browser like Chrome, Firefox or Edge. 另一个演示甚至使用了40000行,如果您使用Chrome,Firefox或Edge等现代网络浏览器,它也可以非常快速地工作。 You should think about the time for sending the data to the server and all overhead of the operation. 您应该考虑将数据发送到服务器的时间以及操作的所有开销。 The usage of loadonce: true simplify both the server code and the client code and improves the responsibility of the grid in the most cases. loadonce: true的用法在大多数情况下都简化了服务器代码和客户端代码,并提高了网格的责任感。 The exact choice is still depend on the total number of rows in the grid. 确切的选择仍然取决于网格中的总行数。 It will be not good for very large number of rows. 对于大量的行来说,这将是不好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM