2013-04-17 3 views
1

테이블이 2 개 있습니다. 고객 담당자. 테이블 연락처에는 고객 테이블을 가리키는 외래 키가 있습니다. 여기 jQuery EasyUI - 셀에 대한 링크 추가

<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 파일 나는 <th field="customer_id" width="50">Customer</th> 연결 가능을 만들고 싶어

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

입니다. 즉 <a href="customerView.php?id=$customer_id>#</a> 테이블을로드 할 때 ID의 고객 이름이 표시되고 고객 페이지 링크가 표시됩니다! 도와주세요. 함께가는

<th data-options="field:'name',width:100,align:'left',formatter:formatCustomerId">Name</th> 

다음 자바 스크립트 기능 : 링크의 종류를 들어

function formatCustomerId(val,row){ 
    var url = "customerView.php?id="; 
    return '<a href="'+url + row.customer_id+'">'+val+'</a>'; 
} 
+0

당신은 너무 jQuery 코드를 게시해야 –

+0

jQuery 코드? –

+0

DataGrid를 시작한 사람 –

답변

3

최종 솔루션은 모든 이전 답변의 혼합물이었습니다 :).

<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

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

?> 
+0

감사합니다. "공식적인"충고는이 "단 하나의 셀 전용 포매터"보다 구현이 훨씬 무거워요 : http://www.jeasyui.com/forum/index.php?topic=1725.0 – AFract

0

내가 데이터 -를 사용하여 어떻게 든 약간의 해결 방법을 관리

이 업데이트

url 속성을 사용하여 리디렉션하려는 URL을 저장 한 다음 jquery를 사용하여 사용자를 리디렉션합니다 (예 :

).

<td class='customer_whatever' data-url='<?= $customer_page_url ?>'> Customer Name</td> 

jQuery를 모두를 잡아 온 클릭 이벤트 추가 :

$('td').each(function(){ 
    if($(this).data('url')){ 
     $(this).click(function(){ 

     $(location).attr('href',$(this).data('url')); 
     }); 
    } 
}); 

을 당신이 링크를 연결하려는 데이터-url 속성 쓰기, 테이블을 생성하면 서버 측에서

CSS를 넣어하는 것을 잊지 마세요 :

.customer_whatever{ cursor:pointer;} 

이 작은 작업 예입니다 http://jsfiddle.net/9XA3k/1/

+0

이 경우의 문제점은 태그를 제어 할 수 없다는 것입니다. 나는 태그를 제어 할 수 밖에 없다. 태그에 개별적으로 액세스하고 json 배열에서 가져 오는 내용을 사용자 정의하려면 어떻게합니까? –