1

我用过 kendoui 网格之类的;

<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

1 回答 1

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);
}
于 2013-03-22T15:02:52.197 回答