jQuery EasyUI-将链接添加到单元格
我有两张表:客户联系。Table contact有一个外键指向customer表jQuery EasyUI-将链接添加到单元格,jquery,Jquery,我有两张表:客户联系。Table contact有一个外键指向customer表 <table id="dgContactSearch" title="Suche" class="easyui-datagrid" style="height:160px" url="getContacts.php" toolbar="#toolbarContactSearch" paginati
<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>
我想使客户
可链接。i、 e.
因此,当我加载表格时,我会看到id中的客户名称,并链接到客户页面!
请帮忙
更新
我设法解决了一些问题:
<th data-options="field:'name',width:100,align:'left',formatter:formatCustomerId">Name</th>
名称
然后是Javascript函数:
function formatCustomerId(val,row){
var url = "customerView.php?id=";
return '<a href="'+url + row.customer_id+'">'+val+'</a>';
}
函数格式CustomerID(val,行){
var url=“customerView.php?id=”;
返回“”;
}
对于此类链接,我使用数据url属性保存要重定向的url,然后使用jquery重定向用户,例如:
在服务器端生成表时,在要关联链接的位置写入数据url属性:
<td class='customer_whatever' data-url='<?= $customer_page_url ?>'> Customer Name</td>
在css中,不要忘记放置:
.customer_whatever{ cursor:pointer;}
这是一个小的工作示例:最终的解决方案是前面所有答案的混合:)
昆德
名称
功能
电话
电子邮件
可移动的
传真
科门塔雷
剧本:
<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>
函数格式CustomerID(val,行){
var url=“customerView.php?id=”;
返回“”;
}
函数formatContactUrl(val,行){
var url=“contactView.php?id=”;
返回“”;
}
以及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代码,这是一个启动DataGrid的代码,只需编写一个查询来提取客户名称,如从客户cus中选择cus.customer\u name,联系con,其中cus.id=con.id
。因此,您可以在ID中使用名称,并通过jquery使其可链接。您希望在客户单元格上的表体tr中的链接在哪里?是的!我希望链接位于客户单元格中。本例中的问题是我无法控制标签。我只能控制标签。我如何单独访问标签并自定义来自json数组的内容???谢谢。“官方”建议比“仅一个单元格的格式化程序”更难实现:
<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>
<?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);
?>