jQuery EasyUI - 添加指向单元格的链接 [英] jQuery EasyUI - Add link to cell
问题描述
我有2个表:客户联系人。表联系人有一个指向客户表的外键。
I have 2 tables: Customer Contact. Table contact has a foreign key pointing at the customer table.
<table id="dgContactSearch" title="Suche" class="easyui-datagrid" style="height:160px"
url="getContacts.php"
toolbar="#toolbarContactSearch" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="customer_id" width="50">Customer</th>
<th field="name" width="50">Name</th>
<th field="function" width="50">Funktion</th>
<th field="phone" width="50">Phone</th>
<th field="mobile" width="50">Mobile</th>
<th field="fax" width="50">Fax</th>
<th field="email" width="50">Email</th>
<th field="comment" width="50">Commnent</th>
</tr>
</thead>
</table>
这里是php文件
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$searchItemContact = isset($_POST['searchItemContact']) ? mysql_real_escape_string($_POST['searchItemContact']) : '';
$searchItemContact = htmlentities($searchItemContact, ENT_QUOTES, 'UTF-8');
$offset = ($page-1)*$rows;
$result = array();
$where = "name like '%$searchItemContact%' OR function like '%$searchItemContact%' OR email like '%$searchItemContact%' OR comment like '%$searchItemContact%'";
$rs = mysql_query("select count(*) from contact where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select * from contact where " . $where . " limit $offset,$rows");
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
我想要< th field =customer_idwidth = 50>客户< / th>
可链接。 ie < a href =customerView.php?id = $ customer_id>#< / a>
所以当我加载表格时,我看到了客户名称安装了id并链接到客户页面!
请帮忙。
I want to make the <th field="customer_id" width="50">Customer</th>
linkable . i.e. <a href="customerView.php?id=$customer_id>#</a>
So when I load the table I see the customer name instaed of the id and make a link to th e customer page!
Please help.
更新
我以某种方式管理了一些解决方法:
I managed somehow a little workaround:
<th data-options="field:'name',width:100,align:'left',formatter:formatCustomerId">Name</th>
然后是Javascript函数:
and then Javascript function that goes along:
function formatCustomerId(val,row){
var url = "customerView.php?id=";
return '<a href="'+url + row.customer_id+'">'+val+'</a>';
}
推荐答案
最终解决方案是以前所有答案的混合:) 。
Final solution was a mixture of all the previous answers :).
<table id="dgContactSearch" title="Benutzer Suche" class="easyui-datagrid" style="height:160px"
url="getContacts.php"
toolbar="#toolbarContactSearch" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th data-options="field:'firma',width:80,align:'left',formatter:formatCustomerId">Kunde</th>
<th data-options="field:'name',width:50,align:'left',formatter:formatContactUrl">Name</th>
<th field="function" width="50">Funktion</th>
<th field="phone" width="50">Phone</th>
<th field="email" width="50">Email</th>
<th field="mobile" width="50">Mobile</th>
<th field="fax" width="50">Fax</th>
<th field="comment" width="120">Kommentare</th>
</tr>
</thead>
</table>
剧本:
<script>
function formatCustomerId(val,row){
var url = "customerView.php?id=";
return '<a href="'+url + row.customer_id+'">'+val+'</a>';
}
function formatContactUrl(val,row){
var url = "contactView.php?id=";
return '<a href="'+url + row.id+'">'+val+'</a>';
}
</script>
和getContacts.php
and the getContacts.php
<?php
include 'includes/db_functions.php';
db_link();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$searchItemContact = isset($_POST['searchItemContact']) ? mysql_real_escape_string($_POST['searchItemContact']) : '';
$searchItemContact = htmlentities($searchItemContact, ENT_QUOTES, 'UTF-8');
$offset = ($page-1)*$rows;
$result = array();
$where = "name like '%$searchItemContact%' OR function like '%$searchItemContact%' OR customer.name like '%$searchItemContact%' OR email like '%$searchItemContact%' OR comment like '%$searchItemContact%'";
$rs = mysql_query("select count(*) from contact where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$sql = "SELECT contact.*, customer.name
FROM `contact`
INNER JOIN `kunden` on contact.customer_id = kunden.id ";
$rs = mysql_query($sql . "where " . $where . " limit $offset,$rows");
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
?>
这篇关于jQuery EasyUI - 添加指向单元格的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!