Jquery Jqgrid在网格中显示图像?

时间:2011-08-23 22:33:43

标签: php jquery mysql jqgrid-php

这是我的代码:

<?php
require_once '../../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."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 p.product_id, p.product_title, p.product_image1_t2, pc.product_cat_name, b.brand_name FROM ' . DB_PRODUCTS .'  p INNER JOIN ' . DB_PRODUCT_CATS . ' pc ON p.product_cat_id=pc.product_cat_id LEFT JOIN ' . DB_BRANDS . ' b ON b.brand_id=pc.product_cat_brand_id';
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model from SQL query
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
// Set alternate background using altRows property
$grid->setGridOptions(array(
    "rowNum"=>10,
    "sortname"=>"product_id",
    "rowList"=>array(10,20,50),
    "height"=>'auto',
    "grouping"=>true,
    "groupingView"=>array(
        "groupField" => array('brand_name'),
        "groupColumnShow" => array(true),
        "groupText" =>array('<b>{0}</b>'),
        "groupDataSorted" => true

    ) 
    ));
// Change some property of the field(s)
$grid->setColProperty("product_id", array("label"=>"NO", "width"=>60));
$grid->setColProperty("brand_name", array("label"=>"BRAND"));
$grid->setColProperty("product_title", array("label"=>"PRODUCT NAME"));
$grid->setColProperty("product_cat_name", array("label"=>"CATEGORY"));
$grid->setColProperty("product_image1_t2", array("label"=>"PRODUCT PHOTO"));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>

所以,我成功获取了我的整个数据但是,当我调用此文件时,我在“product_image1_t2”(PRODUCT PHOTO)网格中看到了我的文件名称,例如: “image_file.jpg”。我希望将图像显示为显示的内容

<img src="myfile.jpg" alt="my_file.jpg" />

已经检查手册但不明白,所以我是jquery的新手......

你可以帮助我这个例子怎么做? 在这里你可以看到当前的结果:

http://oi55.tinypic.com/11qolsz.jpg

1 个答案:

答案 0 :(得分:0)

查看the JQGrid forum,有几个主题讨论如何在网格中集成图像,如this one或此处SO,image column in jqGrid?