【问题标题】:removing columns from jqgrid从 jqgrid 中删除列
【发布时间】:2012-01-14 20:52:39
【问题描述】:

我想在jqgrid中添加我自己的列名,并且我想防止php-jqgrid根据sql查询自动添加的列名。

我正在使用 php-jqgrid。

实际上 jqgrid 从 mysql 表的列名中获取列名,而我的 db 表大约有 55 列,但所有列都是进一步计算所必需的。所以我只想打印 12 个选定的列,而不是所有其他的其余列。

我正在禁用这样的其他列:-

$grid->setColProperty("lat", array("hidden"=>true));
$grid->setColProperty("lng", array("hidden"=>true));
$grid->setColProperty("clinic_id", array("hidden"=>true));
$grid->setColProperty("id", array("hidden"=>true));
.....
.....
.....

但是将每一列设置为隐藏/禁用很复杂。需要将每列设置为隐藏/禁用的代码。

是否有任何排序方法可以隐藏/禁用网格中的其余列。

我正在使用此代码来执行此操作,但它还获取了我未在 $grid->setColModel(null, null, $mylabels); 方法中声明的列的名称;

谁能告诉我我应该写什么短代码来删除jqgrid中额外添加的列。

非常感谢。

require_once '/var/www/html/zbajtmp/public/jqgrid/jq-config.php';
// include the jqGrid Class
require_once "/var/www/html/zbajtmp/public/jqgrid/php/jqGrid.php";
// include the driver class
require_once "/var/www/html/zbajtmp/public/jqgrid/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);
 // Write the SQL Query
//$grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, Freight, ShipName  FROM orders';
$grid->SelectCommand = 'SELECT *  FROM clinic';
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
//$grid->setColModel();
$mylabels = array(
"clinic_name"=>"Clinic ame",
"clinic_address"=>"Address",
"HomePhone"=>"Home Phone",
"WorkPhone"=>"Work Phone",
"Email_Id"=>"Email",
);
// Let the grid create the model with the desired labels
$grid->setColModel(null, null, $mylabels);

$grid->setColProperty("lat", array("hidden"=>true));
$grid->setColProperty("lng", array("hidden"=>true));
$grid->setColProperty("clinic_id", array("hidden"=>true));
$grid->setColProperty("id", array("hidden"=>true));
.....
.....
.....
// Set the url from where we obtain the data
//$grid->setUrl('/var/www/html/zbajtmp/application/views/scripts/clinic/grid.php');
$grid->setUrl('http://sunlinux/zbajtmp/application/views/scripts/clinic/grid.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
    "caption"=>"This is my custom Caption...",
    "rowNum"=>50,
    "sortname"=>"id",
    "hoverrows"=>true,
    "rowList"=>array(20,50,100,1000),
    "width"=>"100%",
    "height"=>350,
"footerrow"=>true,
"rownumbers"=>true,
"multiselect"=>true,
"altRows"=>true,
"altclass"=>'clsalt',
"loadtext"=>"<div class='loadingbox'>Please wait. Loading...</div>",

    ));


$grid->renderGrid('#grid','#pager',true, null, null, true,true);


$conn = null;  

非常感谢。

【问题讨论】:

    标签: jquery jqgrid jqgrid-php jqgrid-formatter


    【解决方案1】:

    jqGrid 使用 selectCommand 构建 colModel - 因此您需要隐藏手动渲染不需要的额外列 - 我建议您从 select 语句中删除 * 并选择您需要的列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多