【问题标题】:JQgrid style issue with Twitter BootstrapTwitter Bootstrap 的 JQgrid 样式问题
【发布时间】:2013-04-17 03:24:44
【问题描述】:

我正在使用 JQgrid 来显示信息并执行 CRUD 操作。我想要一个具有 Twitter Bootstrap 外观和感觉的页面以及显示一些数据的 JQGrid,但是如果我导入 JQGrid 的 CSS 和 Bootstrap 的 CSS,则网格根本不可见。我基本上想要的是将 JQGrid 样式与其他页面样式完全分开。

这可能吗?

下面是我尝试将 Twitter Bootstrap 与 JQGrid 一起使用的页面代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <!--Styles for JQGrid-->
    <link rel="stylesheet" type="text/css" media="screen" href="/css/flick/jquery-ui-1.8.16.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="/jqgrid/css/ui.jqgrid.css" />

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
    <script src="/jqgrid/js/i18n/grid.locale-es.js" type="text/javascript"></script>
    <script src="/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>


    <!--Twitter Bootstrap Styles -->

        <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">

        <script src="http://code.jquery.com/jquery.js"></script>
        <script src="/bootstrap/js/bootstrap.min.js"></script>

<title>Manejo de alumnos</title>
</head>
<body>
<center>

    <div class="myjqueryUI">
        <table id="list"></table><!--Grid table-->
        <div id="pager"></div>  <!--pagination div-->
        <a href="http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Alumnos_controller/mostrarInsertar">Insertar alumno</a>
    </div>

</center>

<script type="text/javascript">


    $(document).ready(function (){
        jQuery("#list").jqGrid({
            url: 'http://localhost/ProyectoNetbeans/CodeIgniter_2.1.3/index.php/Alumnos_controller/loadData',
            mtype : "post",             //Ajax request type. It also could be GET
            datatype: "json",            //supported formats XML, JSON or Arrray
            colNames:['Expediente','Primer apellido','Segundo apellido', 'Nombre','Cédula'],       //Grid column headings
            colModel:[
                {name:'expediente',index:'expediente', width:300, editable:true, edittype:'text'},
                {name:'primerApellido',index:'primerApellido', width:300, editable:true, edittype:'text'},
                {name:'segundoApellido',index:'segundoApellido', width:300, editable:true, edittype:'text'},
                {name:'nombre',index:'nombre', width:300, editable:true, edittype:'text'},
                {name:'cedula',index:'cedula', width:300, editable:true, edittype:'text'}

            ],
            pager: '#pager',
            rowNum:10,
            rowList:[15,30],
            sortname: 'primerApellido',
    reloadAfterSubmit: true,
            sortorder: 'asc',
            viewrecords: true,
    postData: {expediente:"expediente"},
            caption: 'Alumnos'
        }).navGrid('#pager',{edit:false,add:false,del:false},
            {

            },
            {
              },


    },  

    {multipleSearch : false}, // enable the advanced searching
    {closeOnEscape:true}

        );
    });
</script>

【问题讨论】:

    标签: css twitter-bootstrap jqgrid


    【解决方案1】:

    您不仅应该发布您所做的描述,还应该发布显示如何您尝试这样做的代码(HTML、JavaScript 等)。

    如果您想将 jqGrid 放置在主要使用 Twitter Bootstrap 的页面上,我建议您使用特殊的 jQuery UI:jQuery UI Bootstrap

    如果你更喜欢使用其他一些 jQuery UI CSS,你可以从官方jQuery UI download page 下载你需要的 CSS,但是在“CSS Scope:”字段中设置一些类名:

    如果您在“CSS Scope:”字段中输入例如“.myjqueryUI”,那么您需要将用于 jqGrid 的 &lt;table&gt; 放置在具有“myjqueryUI”类的 &lt;div&gt; 内:

    <div class="myjqueryUI">
        <table id="grid"></table>
    </div>
    

    【讨论】:

    • 感谢 Oleg 的回复,抱歉没有发布代码,我已经将它包含在原始帖子中。我下载了 JQuery UI Bootstrap 并将其包含在我的项目中,但我不知道您打开的“CSS 范围”页面在哪里。我尝试在 div 中为 JQGrid 表设置一个类,但没有工作。我打开了 JQuery UI bootstrap 的 CSS 文件,但我不确定应该为包含表的 div 使用哪一个。你知道JQuery UI Bootstrap需要用到什么吗?
    • @Vito:您可以下载标准的 jQuery UI 主题(链接 Flick Theme,您当前使用的主题)或使用 JQuery UI Bootstrap。您可以在the download page 上找到“CSS Scope”字段。只能下载页面上可用的标准主题(如Flick Theme)。对您的代码的一点说明:您应该包含 only 一个 jQuery JavaScript。您当前的代码首先包含 jQuery 1.7.1,然后是 jQuery 1.9.1(在 bootstrap.min.js 之前)。
    • @SuhailGupta:jQuery UI 允许定义不同的ThemesjQuery UI Bootstrap 是 jQuery UI 的主题,这使得 jQuery UI 看起来非常接近 Twitter Bootstrap,但它仍然只是一个主题(一种风格)。它不会改变 jqGrid 的 特性 中的任何内容。
    • @SuhailGupta:免费 jqGrid 的完整代码现在包含 18000 行。该代码不是最佳原因,并且可能包含许多您不需要的功能。不过,最好将 jqGrid 想象为 Web 组件(控件为黑盒),就像 HTML 表格一样。
    • @SuhailGupta:我在免费的 jqGrid fork 中实现的第一个功能是与 Bootstrap 的兼容性。在此之前,我发布了一些纯 CSS 更改的初步版本here。我建议您尝试将 URL(测试临时)更改为 the wiki article 中描述的免费 jqGrid 的 URL。您将看到现有代码在免费 jqGrid 中的外观。查看自述文件和 wiki 了解更多信息
    【解决方案2】:

    检查这个Bootstrap UI Template包含jqGrid插件

    您可以使用此模板中的许多功能。看起来很棒

    【讨论】:

      【解决方案3】:

      关于 jqGrid + Bootstrap 的附加信息:

      jqGrid (4.6.0) 和 Bootstrap (3) 似乎存在表格边框折叠覆盖问题。

      jqGrid 想要:border-collapse: separate;(CSS 默认)

      Bootsrap 想要:border-collapse: collapse;

      导致网格右侧出现溢出问题。

      #grid_container_id table{
          border-collapse: separate;
      }
      

      解决了这个问题。

      【讨论】:

        【解决方案4】:

        这对我们有用:

        1- 从 https://github.com/Soliman/jqGrid.bootstrap 获取 css

        这不会改变任何 jqgrid 规范,只改变一些 css。

        演示在http://www.soliman.nl/test/jqgrid.bootstrap/jqGrid.bootstrap.html

        2- 如果您希望所有引导 css 都适用于您的表,您必须在网格加载后运行以下命令:

        //remove the 'ui-state' and 'ui-widget' from jquery-ui.css which prevents your customize ccs to apply on  jquery grid 
        //the gbox_gridtable is the most top element in the grid
        function removeJqueryUiClass(){
            $('#gbox_gridtable').find('*').andSelf().attr('class',
                    function(i, css){
                        if (typeof css !== 'undefined') {                    
                               return css.replace(/\ui-state\S+/g, '').replace(/\ui-widget\S+/g, '');
                            }
                   });
        
        }
        

        3- 要让 jqgrid 响应,请将您的网格放在像 &lt;div id="grid"&gt; 这样的 div 中:当然,这个 div 必须是引导网格系统的一部分,然后将下面的 js 放在您的文件中

        //When the window size changes resize the gird
        $(window).bind('resize', function() {
            $("#gridtable").jqGrid("setGridWidth",$("#grid").width() );
        });
        

        4- 您也可以在网格完全加载时设置网格大小

        【讨论】:

          【解决方案5】:

          新版 jqGrid 5.0 原生支持 Bootstrap。 http://www.trirand.com/blog/?p=1484

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-11-07
            • 1970-01-01
            • 1970-01-01
            • 2013-07-30
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多