2

希望有人能指出我正确的方向..

我有时会面临这个问题。!

http://imgur.com/j8S9ft5

我尝试了一些从 stackoverflow 中找到的解决方案

例如jqGrid 列未与列标题对齐

和其他来源,但没有解决我的问题。这个问题只有在升级到 Chrome 19 及更高版本(我认为!)和 safari 6 后才会出现。我注意到在使用 safari 5 的第二台计算机上查看时以及重新安装 Chrome 版本 18 时没有问题。

我尝试通过从 trirand.net 下载来更新一些 js 和 css 文件,但没有解决方案。

目前我正在运行 Safari 版本 6.0.1 (8536.26.14) 和 Chrome 版本 26.0.1410.43。

谢谢

更新 2:更新到 4.4.5 图像http://imgur.com/NlY786x后 我忘了提到这只有在我集成到灯箱(脸箱)中时才会发生

更新 3: @Oleg 我只是在更新到 4.4.5 后才意识到,或者只是粘贴你的代码(在评论中)我不能再使用我的自定义按钮了(工作 b4).. 什么都没有发生。

我正在使用 javascript 和 php jqgrid,下面是我的代码:

<div align="center" id="grido"> </div>  
<script type="text/javascript">
 //var lastSel;
$(document).ready(function(){ 
//  $('#grido').load('form/housekeeping/dun_grid.php');
});
</script>

<script type="text/javascript">
<!-- dun_grid.js  --> 

jQuery(document).ready(function(){

  var lastSel;

 jQuery("#dun_grid").jqGrid({
  url:'form/housekeeping/dun_griddata.php',
  datatype: "json",
  colNames:['DUN ID','DUN Code', 'DUN Name'],    
  colModel:[
      {name:'int_dunid',index:'int_dunid', hidden:true, align:"center", width:50},
      {name:'txt_dcode',index:'txt_dcode', editable:true, align:"center", width:150},
      {name:'txt_dname',index:'txt_dname', editable:true, align:"center", width:150},

          ],
  pager: '#pagerdun', //pagination enable
  rowNum:15,
  rowList:[10,20,30],
  width:430,
  height:'auto',
  sortname: 'txt_dcode',
  sortorder: 'asc',
  hidegrid: false,  //show/hide  grid button on caption header

  viewrecords: true, //display the number of total records
  editurl:"form/housekeeping/dun.php?mode=edit",
  loadtext: "Loading Data, Please Wait...",
  rownumbers:true, // add row numbers on left side
  caption: '&nbsp; DUN List',


 ondblClickRow: function(id){
     if(id && id!==lastSel){ 
       jQuery('#dun_grid').restoreRow(lastSel); 
       lastSel=id; 
    } 
    jQuery('#dun_grid').editRow(id, true, "", refreshing); 
 },

  onSelectRow: function(id){ 
    if(id && id!==lastSel){ 
       jQuery('#dun_grid').restoreRow(lastSel); 
       lastSel=id; 
    }  
 },  


}); /* end of jqgrid */


    jQuery("#dun_grid").jqGrid('navGrid','#pagerdun',{edit:false, add:false, view:false, del:true, search:true}, 
      {}, // edit
      {}, // add
      {url: 'form/housekeeping/dun.php?mode=delete'},  // delete
      {multipleSearch : true},
      {closeOnEscape:true} 
      );  //end on navgrid

    jQuery("#dun_grid").jqGrid('navButtonAdd','#pagerdun',{caption:"", buttonicon :'ui-icon-plus', 

        onClickButton:function(id){
          jQuery('#dun_grid').restoreRow(lastSel);

              var datarow = {txt_dname:""};
              jQuery("#dun_grid").addRowData("0",datarow,"first");
              jQuery('#dun_grid').editRow("0", true, "", tiesto);
              lastSel=id;
          },//end of onClickButton
        title:"New Record", 
        position:"last"
        }); //end of custom button


function refreshing(id){ /* refresh grid */
    jQuery('#dun_grid').trigger("reloadGrid");
    $.blockUI({ message:"Saving Data!!"}); 
        setTimeout($.unblockUI, 700); 
    } 

function tiesto(){
    jQuery('#dun_grid').restoreRow(lastSel);
   jQuery('#dun_grid').trigger("reloadGrid");
    $.blockUI({ message:"New Data Saved!!"}); 
        setTimeout($.unblockUI, 700); 
    } 


});  /*end of document ready*/
</script>


<div align="center" class="gridpanel" >   
<!--------------------------- ## grid for add/edit ## ------------------------------------------>
   <table id="dun_grid" class="scroll" cellpadding="0" cellspacing="0"></table>
  <!-- pager definition -->
  <div id="pagerdun" class="scroll" style="text-align:center;"></div>

 </div> <!----------------------- grid panel end -------------------------------------->

PHP

<?php 
 ini_set("display_errors","1"); 
require_once('../../Connections/jq-config.php');

// include the jqGrid Class 
require_once  "../../phpgrid/php/jqGrid.php";
// include the driver class
require_once "../../phpgrid/php/jqGridPdo.php";
// Connection to the server 
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 
 // Tell the db that we use utf-8 
$conn->query("SET NAMES utf8"); 

// Create the jqGrid instance 
$grid = new jqGridRender($conn); 
$grid->SelectCommand = 'SELECT int_bankid, txt_bank_code , txt_bank_name, txt_bank_address FROM tbl_bank'; 

// set the ouput format to json 
$grid->dataType = 'json'; 
$grid->table ="tbl_bank"; 
$grid->setPrimaryKeyId("int_bankid"); 

$grid->setColModel(); 
$grid->setUrl('form/housekeeping/bank_grid.php'); 
$grid->setGridOptions(array("editurl"=>"form/housekeeping/bank.php?mode=edit"));


// Set grid option
$grid->setGridOptions(array( 
    "caption"=>"&nbsp; List of Banks", 
    "rownumbers"=>true,
    "rowNum"=>10, 
    "rowList"=>array(10,20,50), 
    "sortname"=>"txt_bank_code", 
    "hoverrows"=>true,
    "hidegrid"=>false, 
    "height"=>'auto', 
    "width"=>460, 
        "sortorder"=>'desc', 
    "loadtext" => "meloading data...",
    "cmTemplate"=>array("searchoptions"=>array("sopt"=>array('eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc')))
    )); 

// Change some property of the field(s) 
$grid->setColProperty("int_bankid", array("label"=>"ID", "width"=>50, "align"=>"center", "hidden"=>true)); 
$grid->setColProperty("txt_bank_code", array("label"=>"Code", "width"=>60, "align"=>"center", "editrules"=>array("required"=>true))); 
$grid->setColProperty("txt_bank_name", array("label"=>"Name", "width"=>130, "align"=>"center", "editrules"=>array("required"=>true))); 
$grid->setColProperty("txt_bank_address", array("label"=>"Address", "width"=>200, "align"=>"center")); 

// enable navbutton 
$grid->navigator = true; 

    $grid->setNavOptions('navigator', array("pdf"=>false,"excel"=>false,"add"=>false,"edit"=>false,"del"=>true,"view"=>false )); 
    $grid->setNavOptions('del',array("url"=>"form/housekeeping/bank.php?mode=delete")); 

// jscript for adding new row       
 $reloading = <<<RELOAD
 function(id)
  {
     jQuery("#grid").trigger('reloadGrid');
  }
RELOAD;

 $mycode = <<<NEWBUTTON
 function(id)
  {
    jQuery("#grid").jqGrid('restoreRow',lastSel);
    jQuery("#grid").jqGrid('addRowData',"0",{txt_bank_code:''},"first");
    jQuery("#grid").jqGrid('editRow', "0", true,'',$reloading); 
    lastSel=id;
  }
NEWBUTTON;

//jscript for inline editing    
$editrow = <<<DOUBLECLICK
  function(rowid)
  {
      if (rowid && rowid !== lastSel) {
          jQuery("#grid").jqGrid('restoreRow', lastSel); 
          lastSel = rowid; 
      } 
         jQuery("#grid").jqGrid('editRow', rowid, true,'',$reloading); 
  }
DOUBLECLICK;

//custom button setting for adding new row
$buttonoptions = array("#pager", array("caption"=>"", 'buttonicon' =>'ui-icon-circle-plus', "onClickButton"=> "js:".$mycode));

// inserting custom button
$grid->setGridEvent('ondblClickRow', $editrow);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);
$grid->renderGrid('#grid','#pager',true, null, null, true,true); 
$conn = null; 


?>  
4

4 回答 4

1

我遇到了同样的问题,并且能够通过调整 CSS 来解决它。我已经设置paddingth导致问题的原因。

th的继承padding可能会破坏对齐方式。

如果 上的填充th与网格单元格不同(尤其是padding-leftright),它将破坏对齐。

于 2013-12-20T16:59:39.680 回答
0

尝试将属性设置shrinkToFittrue;

shrinkToFit : true,

维基中给出的

如果设置此选项,则定义应如何重新计算网格列的宽度,同时考虑到网格的宽度。如果此值为真,并且列的宽度也已设置,则每列都按其宽度成比例缩放。例如,如果我们定义了宽度为 80 和 120 像素的两列,但希望网格的宽度为 300 像素,那么这些列将拉伸以适应整个网格,并且分配给它们的额外宽度将取决于宽度列本身和可用的额外宽度。
于 2013-04-03T09:52:11.793 回答
0

将此代码添加到gridComplete网格的事件中。不要忘记gridName用你的网格替换id

var objHeader = $("table[aria-labelledby=gbox_" + gridName+ "] tr[role=rowheader] th");

for (var i = 0; i < objHeader.length; i++) {
   var col = $("table[id=" + gridName+ "] td[aria-describedby=" + objHeader[i].id + "]");
   var width= col.outerWidth();
   $(objHeader[i]).css("width", width);
}

适用于 v.4.6.0。

于 2014-03-12T22:12:15.730 回答
0

我的情况

  1. jqgrid 版本 4.6.0

  2. 网格中的组标题

  3. shrinkTofit 不起作用

  4. 我在 gridComplete 事件中调用了以下函数

    函数 alignColumnsWithHeadersGENEL(gridName) {

     var objHeaders = $("table[aria-labelledby=gbox_" + gridName + "] tr[class=jqg-first-row-header] th");
     var objColumns = $("table[id=" + gridName + "] tr[class=jqgfirstrow] td");
     for (var i = 0; i < objHeaders.length; i++) {
         objHeaders[i].style.width = objColumns[i].style.width;
     }
    

    }

  5. 为我的网格生成的 HTML 的结构类似于以下内容(删除不必要的填充)

  6. 不知何故,标题和列的宽度之间存在差异

于 2020-09-01T09:18:34.890 回答