2013-03-22 50 views
1

我已經使用了kendoui網格;KendoUI:獲取按鈕上的ID點擊PHP

<script> 
    $(function(){ 
     $("#grid").kendoGrid({ 
      dataSource:{ 
       transport: { 
        read: "<?php echo base_url() ?>index.php/user_management/manage_users/list_view/" 
       }, 
       schema:{ 
        data: "data" 
       } 
      }, 
      columns: [ 
       { 
        field: "UserID", 
        hidden:true 
       }, 
       { 
        field: "Username", 
        title:"Username" 
       }, 
       { field: "FirstName", 
        title:"First Name" 
       }, 
       {field:"MiddleNames"}, 
       {field:"LastName"}, 
       {field:"City"}, 
       {field:"Email"}, 
       {field:"Actions"}, 
       {command: { text: "View", click: showDetails }, title: " ", width: "140px"} 
      ] 
     }); 

    }); 


    function showDetails(e) { 
     e.preventDefault(); 

     //i want to get the id of the clicked row and pass that id to the next(redirected) page; 
    } 
</script> 

我如何獲取當前點擊的行ID即UserId列值和ID(重定向)傳遞到下一個頁面?

回答

4

從您收到的情況下,你得到它屬於該行:

var row = $(e.target).closest("tr"); 

然後你使用dataItem項目:

var item = $("#grid").data("kendoGrid").dataItem(row); 

因此,這將是:

function showDetails(e) { 
    var row = $(e.target).closest("tr"); 
    var item = $("#grid").data("kendoGrid").dataItem(row); 
    alert("UserId is:" + item.UserId); 
} 
+0

我如何獲得UserId字段值? – 2013-03-22 15:07:43

+0

看到undefined – 2013-03-22 15:09:21

+0

var grid = $(「#grid」)。data(「kendoGrid」); var da = e.data.valueOf(「FirstName」); alert(da); 但只獲取對象對象,但我想要的值 – 2013-03-22 15:13:10