【问题标题】:How to show horizontal scroll bar in jqgrid如何在jqgrid中显示水平滚动条
【发布时间】:2013-06-01 18:58:33
【问题描述】:

我有一个宽 jqgrid,我通过 width 属性缩小了它。当我使用它时,不会出现水平滚动条。怎么显示?

任何帮助将不胜感激,

谢谢

詹姆

编辑:

这是我目前拥有的 JS 代码。滚动条仍未显示:

<script type="text/javascript">
$(function () {
    $("#personal").jqGrid({
        url: "@Url.Action("List")",
        datatype: "json",
        mtype: "GET",
        colNames: ["Departamento",
                   "Nombres",
                   "Apellido Paterno",
                   "Apellido Materno",
                   "RUT",
                   "Contraseña",
                   "Fecha Nacimiento",
                   "Fotografía",
                   "Estado Civil",
                   "Género",
                   "Dirección",
                   "Cargo",
                   "E-mail",
                   "Fecha Ingreso",
                   "Creación",
                   "Modificación",
                   " "],
        colModel: [
            { name: "departamento", index: "dep_nombre", editable: true, edittype: "select", editoptions: { width: 100, dataUrl: "@Url.Action("GetDepartments","Departamento")" }, width: 250, editrules: { required: true } },
            { name: "per_nombres", index: "per_nombres", editable: true, width: 250, editoptions: { maxlength: 80, size: 32 }, editrules:{ required:true } },
            { name: "per_apellido_paterno", index: "per_apellido_paterno", editable: true, width: 250, editoptions: { maxlength: 80, size: 32 }, editrules: { required: true } },
            { name: "per_apellido_materno", index: "per_apellido_materno", editable: true, width: 250, editoptions: { maxlength: 80, size: 32 } },
            { name: "per_dni", index: "per_dni", editable: true, width: 100, editoptions: { maxlength: 20, size: 17 }, editrules: { required: true } },
            { name: "per_contrasena", editable: true, width: 100, editoptions: { maxlength: 50, size: 17 }, editrules: { required: false } },
            { name: "per_fecha_nacimiento", index: "per_fecha_nacimiento", editable: true, width: 100, editrules: { date: true }, formatter: 'date', formatoptions: {srcformat: 'SortableDateTime', newformat: 'd-m-Y'}, editoptions: { size: 17, dataInit: function (el) { $(el).datepicker({ dateFormat: 'dd-mm-yy' }); } }, },
            { name: "per_fotografia", index: "per_fotografia", editable: true, width: 250, edittype: "file", editoptions: { maxlength: 255, size: 32 } },
            { name: "per_estado_civil", index: "per_estado_civil", editable: true, edittype: "select", editoptions: { value: "S:Soltero; C:Casado; V:Viudo; D:Divorciado" }, width: 100 },
            { name: "per_sexo", index: "per_sexo", editable: true, edittype: "select", editoptions: { value: "M:Masculino; F:Femenino" }, width: 100 },
            { name: "per_direccion", index: "per_direccion", editable: true, width: 250, editoptions: { maxlength: 512, size: 32 } },
            { name: "per_cargo", index: "per_cargo", editable: true, width: 100, editoptions: { maxlength: 50, size: 32 } },
            { name: "per_email", index: "per_email", editable: true, width: 100, editoptions: { maxlength: 80, size: 32 }, editrules: { email: true } },
            { name: "per_fecha_ingreso", index: "per_fecha_ingreso", editable: true, width: 100, editrules: { date: true }, formatter: 'date', formatoptions: {srcformat: 'SortableDateTime', newformat: 'd-m-Y'}, editoptions: { size: 17, dataInit: function (el) { $(el).datepicker({ dateFormat: 'dd-mm-yy' }); } }, },
            { name: "per_creado_el", index: "per_creado_el", editable:false, search:false, width: 100, align: "center", formatter: "date" },
            { name: "per_modificado_el", index: "per_modificado_el", editable:false, search:false, width: 100, align: "center", formatter: "date" },
            { name: 'acciones', width: 58, fixed: true, sortable: false, resize: false, search:false, formatter: 'actions', formatoptions: { keys: true } }
        ],
        jsonReader: {
            repeatitems: false,
            id: "per_id"
        },
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "per_apellido_paterno",
        sortorder: "asc",
        viewrecords: true,
        gridview: true,
        autoencode: true,
        multiselect: true,
        shrinkToFit: false,
        caption: "Funcionarios",
        editurl: "@Url.Action("AjaxEdit")",
        height: '100%',
        width: 935,
        rownumbers: true,
        rownumWidth: 40            
    });

    $("#personal").jqGrid('hideCol', ["per_contrasena", "per_fotografia", "per_direccion"]);
    $("#personal").jqGrid('navGrid', '#pager', { edit: false, add: true, del: true, search: false }, { width: 500 }, { width: 500 }, {}, { multipleSearch: false, multipleGroup: false });
    $("#personal").jqGrid('filterToolbar', { searchOperators: false });

    $.jgrid.edit.addCaption = "Agregar Funcionario o Visita";
    $.jgrid.edit.editCaption = "Modificar Funcionario o Visita";
    $.jgrid.edit.saveData = "¡El funcionario fue modificado! ¿Almacena los cambios?";

    $.jgrid.formatter.date.newformat = 'd-m-Y H:i';
}); 
</script>

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    没有任何代码,有些东西你需要看看......

    不要使用autowidth,并确保你没有使用shrinkToFit(需要设置为false)。除此之外,水平滚动条应该只显示这两个更改。除此之外,您还应该确保为列模型中的每一列明确设置宽度。

    【讨论】:

      【解决方案2】:

      在桌子周围添加一个具有一定宽度和溢出的 div:auto 应该可以解决问题。

      <div style="width:100px;overflow:auto;"><table id="personal"></table><div>
      

      【讨论】:

        【解决方案3】:

        添加

         shrinkToFit : false,
        

        它使表格布局根据单元格大小固定增长,而不是根据表格的父宽度/

        【讨论】:

          【解决方案4】:

          水平滚动条在以下条件下非常适合我:

          1. 设置参数shrinkToFitforceFit。例如:

            $('#gridObtenerRegistros').jqGrid({ shrinkToFit:false, forceFit:true,

            并且不要使用宽度参数。

          2. colmodel 中设置宽度属性。示例:

            colModel:[ {name:'numEmpleadoCliente',index:'numEmpleadoCliente', width:80, sortable: false, resizable: false}, {name:'nombre',index:'nombre', width:215, sortable: false, resizable: false}, {name:'estatus',index:'estatus', width:50, sortable: false, resizable: false}],

          3. 检查.ui-jqgrid .ui-jqgrid-bdiv 类的样式有:`

            overflow: auto;

          4. 检查表格的网格没有宽度属性。

            在我的例子中: &lt;table id="gridBusquedaRegistros"&gt;&lt;/table&gt;

          希望这对任何人都有帮助。

          【讨论】:

            【解决方案5】:

            最后是因为网格中没有显示数据。当网格返回数据时,出现水平滚动条。

            问候, 詹姆

            【讨论】:

              【解决方案6】:

              可能您在页面上定义了一些其他的 CSS,这会产生问题。 The demo 仅使用您的代码会显示水平滚动条。

              【讨论】:

                【解决方案7】:

                您可以尝试如下:

                $('#grid_table').jqGrid({
                    .....
                    colModel: [
                            // you can also set width for individual columns
                            { name: "user_name", align:"center", width: "200"},
                    .....
                    .....
                
                    shrinkToFit: false,
                    .....
                
                    gridComplete: function()
                    {
                     $('#grid_table').jqGrid('setGridWidth', '1000'); // max width for grid
                    },
                    .....
                

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2011-03-06
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-02-14
                  • 2021-11-13
                  相关资源
                  最近更新 更多