简体   繁体   English

从jqgrid删除列

[英]removing columns from jqgrid

I would like to add my own column names in jqgrid and also i want to prevent the column names that is automatically added by php-jqgrid according to sql query. 我想在jqgrid中添加我自己的列名称,并且我想防止php-jqgrid根据sql查询自动添加的列名称。

I am using php-jqgrid. 我正在使用php-jqgrid。

Actually jqgrid getting the column name from mysql table's column name and my db table has about 55 column, but all columns are necessary for further calculations . 实际上jqgrid从mysql表的列名获取列名,而我的db表大约有55列,但是所有列对于进一步的计算都是必需的。 so i want to just print only 12 selected columns not all other rest columns. 所以我只想只打印12个选定的列,而不是其他所有其余列。

I am disabling other column like this :- 我禁用了这样的其他列:-

$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));
.....
.....
.....

But it is complex to set every column hidden/disable. 但是将每个列都设置为隐藏/禁用很复杂。 Requires code for every column set to hidden/disable. 设置为隐藏/禁用的每列都需要代码。

Is there any sort method to hide/disable rest columns form grid. 是否有任何排序方法可以隐藏/禁用表格的其余列。

I am using this code to do that, but its also getting the name of columns which i have not declare in the method $grid->setColModel(null, null, $mylabels); 我正在使用此代码来做到这一点,但它也得到了我在方法$ grid-> setColModel(null,null,$ mylabels)中未声明的列的名称。

Can anyone please tell me what short code i should to write for removing extra added column in jqgrid. 谁能告诉我为删除jqgrid中额外添加的列我应该写什么短代码。

Thanks a lot. 非常感谢。

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;  

Thanks a lot. 非常感谢。

jqGrid使用selectCommand构建colModel因此您将需要隐藏不需要手动呈现的多余列-我建议您从select语句中删除*并仅选择所需的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM