1

我想为 Kendo UI 网格模板按钮分配 ID(来自 dataSource),并想知道来自 cilcked_function() 的单击按钮 ID。任何人都可以帮助我做到这一点..

$("#grid").kendoGrid({
        dataSource: App.TempHourlyTargetData,
        columns: [
            { field: "field1", title: "Field 1", width: "25%" }, { field: "field2", title: "Field 2", width: "25%" },  

            {
                template: "<a href='\\\#' onclick='click_function()' id = '" + id_from_datagrid + "' class='deleteBtn'></a>",
                width: "25%"
            }
        ],

        height: 350,
        change: onChange,
        selectable: "multiple cell",//""multiple row"",  ,
    });
4

3 回答 3

2

是的,您可以通过以下代码实现它:删除您放置在模板中的 onclick 标记:

$("#grid").kendoGrid({
        dataSource: App.TempHourlyTargetData,
        columns: [
            { field: "field1", title: "Field 1", width: "25%" }, { field: "field2", title: "Field 2", width: "25%" },  

            {
                template: "<a href='\\\#' id = '" + id_from_datagrid + "' class='deleteBtn'></a>",
                width: "25%"
            }
        ],

        height: 350,
        change: onChange,
        selectable: "multiple cell",//""multiple row"",  ,
    });

下面的代码将为您提供 id:

    $(document).on('click','.deleteBtn',function(){
       var id=$(this).prop('id');
    })

//或者

    $('.deleteBtn').click(function(){
        var id=$(this).prop('id');
    })
于 2014-03-14T07:37:33.487 回答
0

请注意 user3040830 的回答:如果您的元素是动态加载的,则在加载 DOM 之后,这将起作用 -

$(document).on('click','.deleteBtn',function(){
       var id=$(this).prop('id');
    }) 

但不是这个:

   $('.deleteBtn').click(function(){
        var id=$(this).prop('id');
    })

于 2015-05-20T18:59:04.860 回答
0
       var  grid = $("#GridContainer").kendoGrid({
            columnMenu: false,
            scrollable: true,
            columns: [
                {
                    title: "Button",
                    template: '<div><button id="#= columnNamefromDatabase #" /></div>',
                    width: 80
                },
               {
                   field: Column2,
                   title: "ColumnHeader2",
                   width: 80

               },
               {
                   field: Column3,
                   title: "ColumnHeader3",
                   width: 200
               },

            ],
            resizable: true,
            dataSource: {
                transport: {
                    read: {
                        url: GetDetailsUrl,
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8"

                    },
                    parameterMap: function (options) {
                        options.YourModel = YourModelObect;
                        return JSON.stringify(options);

                    }
                },
                schema: {
                    data: function (response) {
                        var griddetails = response.result;
                        return griddetails;

                    },

                },

                serverPaging: false,
                serverSorting: false,
                selectable: "multiple",

            },
            dataBound: function (arg) {
                var results = arg.sender.dataSource.view();
                ResultItems = results;
                 $( ":button" ).click(function(){                        
                    Id=$(this).prop('id')
                 })

            }
        }).data("kendoGrid");
于 2016-08-09T11:03:54.897 回答