dongluoqiu0255 2011-12-07 08:56
浏览 63

在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 jqgrid according to sql query.

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

Can anyone please tell me what code i should to write for removing extra added column in 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);
// 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.

  • 写回答

1条回答 默认 最新

  • dongxiong5546 2011-12-07 10:02
    关注

    You need to explicitly select the columns you want - SELECT * wont work

    So you need to change :

    $grid->SelectCommand = 'SELECT *  FROM clinic';
    

    to

    $grid->SelectCommand = 'SELECT clinic_name,clinic_address,HomePhone,WorkPhone,Email_Id  FROM clinic'; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制