2011-12-07 80 views
0

我想在jqgrid中添加我自己的列名,並且還想防止由php-jqgrid根據sql查詢自動添加的列名。從jqgrid中刪除列

我正在使用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; 

非常感謝。

回答

0

的jqGrid使用構建colModelselectCommand - 所以你需要隱藏不需要手動繪製額外的列 - 我建議你從select語句刪除*,只是選擇所需的列。