简体   繁体   English

复选框事件未使用jQuery触发

[英]checkbox event is not firing with jquery

I have got checkbox row in parent grid and checkbox row in child grid as well in Hierarchy grid mode using kendo UI . 我在使用Kendo UI的层次结构网格模式下,在父网格中有复选框行,在子网格中有复选框行。 the architecture is like this... 建筑就是这样...

I have got four rows in parent grid,in that one column is checkbox and for every parent row i have got one child grid with 4 rows in it and one checkbox column as well... 我在父网格中有四行,其中一列是复选框,对于每一父行,我都有一个子网格,其中有4行,还有一个复选框列...

If i click the checkbox in parent grid row i need to access the checkboxes in child grid column related to this row only and need to set the checked attribute as true for that child grid..... 如果我单击父网格行中的复选框,则只需要访问与此行相关的子网格列中的复选框,并且需要将该子网格的checked属性设置为true。

for that I am accessing the parent grid checkbox like this .. 为此,我正在访问像这样的父网格复选框。

this is javascript function 这是javascript函数

  <script type="text/javascript">
    $('.chkbxq').live('click', function (e) {
        alert('1'); // this alert is not firing 
        var checkchildgrid = $('#Gridparent').find(".k-detail-row").find('td.k-detail-cell').find('[type="checkbox‌​"]').is(':checked');
        alert(checkchildgrid);
        if ($(this).is(':checked')) {    
            checkchildgrid.attr('checked', 'checked');
        } else {
            checkchildgrid.attr('checked', false);
        }    
    });        
</script>

and this is hierarchy grid code .... 这是层次结构网格代码..

    @model IEnumerable<Topco.TopMapp.MVC.Models.CostPageSearch>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
@using (Html.BeginForm())
{ 
   @(Html.Kendo().Grid<Topco.TopMapp.MVC.Models.CostPageSearch>()
        .Name("Gridparent")
        .Columns(columns =>
        {
            columns.Template(@<text></text>).ClientTemplate("<input id='chqprnt' class= 'chkbxq' type='checkbox'/>").Width(30);
            columns.Bound(e => e.CostPage).Width(100);
            columns.Bound(e => e.Description).Width(100);
            columns.Bound(e => e.VendorName).Width(100);
            columns.Bound(e => e.BillTypeDirect).Width(100);
            columns.Bound(e => e.BillTypeWarehouse).Width(100);
            columns.Bound(e => e.VendorName).Width(100);

        })
        .Sortable()
        .Pageable()
        .Scrollable()
        .ClientDetailTemplateId("client-template")
        .HtmlAttributes(new { style = "height:480px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(6)
            .Read(read => read.Action("HierarchyBinding_Employees", "CostPageDisplay"))
        )
        .Events(events => events.DataBound("dataBound"))
)
    <script id="client-template" type="text/kendo-tmpl">
         @(Html.Kendo().Grid<Topco.TopMapp.MVC.Models.ItemsDescriptionModel>()
            .Name("grid_#=CostPage#")
            .Columns(columns =>
            {
                columns.Template(@<text></text>).ClientTemplate("<input id='checkbox'  class='chkbx' type='checkbox' />").Width(30);
                columns.Bound(o => o.ItemId).Width(100);
                columns.Bound(o => o.ItemDescription).Width(100);
                columns.Bound(o => o.BrandCode).Width(100);
                columns.Bound(o => o.PackSize).Width(100);
            })
           .DataSource(dataSource => dataSource
               .Ajax()
               .PageSize(5)
               .Read(read => read.Action("HierarchyBinding_Orders", "CostPageDisplay" , new { employeeID = "#=CostPage#" }))
           )
           .Pageable()
           .Sortable()
           .ToClientTemplate()
   )
    </script>
<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
        //alert('1');
    }
</script>

but when i click on the checkbox in parent grid the click event is not firing ... 但是当我单击父网格中的复选框时,单击事件未触发...

would any one pls suggest any ideas and solutions with this problem that would be very grateful to me..... 请问有人对这个问题有什么建议和解决办法,我将不胜感激.....

many thanks in advance ... 提前谢谢了 ...

EDIT : would you pls look at the image below that is where i placed the checkbox and clicking on that checkbox does not firing event ... 编辑:请您看下面的图像,这是我放置复选框并单击该复选框不会触发事件的位置...

在此处输入图片说明

Try this, 尝试这个,

 $('#Gridparent').on("click", ".chkbxq", function (e) {

       var selected = $(this).is(':checked');

        var grid = $("#grid12").data("kendoGrid");


        if (selected == true) {

            var check = $('.k-detail-row').find('td.k-detail-cell').find('div.k-grid').find('table').find('tbody').find('[type="checkbox"]').attr('checked', true);
            var asd = check.is(':checked');
            alert(asd);
        }

        });

Use grid click. 使用网格单击。

This is how I imagine it should be coded - disclaimer I do not know Kendo at all 这就是我想像的应该被编码的方式-免责声明我根本不知道剑道

If we need to process the checkboxes as you WRITE, we can do 如果我们需要在您写时处理复选框,则可以执行

$(function() {
  $('.chkbxq').on('click', function (e) {
    var checked = this.checked;
    $('#Gridparent').find(".k-detail-row").find('td.k-detail-cell').find('[type="checkbox‌​"]').each(function()
      this.checked=checked; // toggle
    });    
  });    
});        

If the content is ajaxed in, you need 如果内容被压缩,则需要

$(function() {
  $("#Gridparent").on('click','.chkbxq', function (e) {
    var checked = this.checked;
    $(this).find(".k-detail-row").find('td.k-detail-cell').find('[type="checkbox‌​"]').each(function()
      this.checked=checked; // toggle
    });    
  });    
});        

NOTE .find works all the way down the dom, so perhaps you just want 注意 .find一直沿dom运行,所以也许您只想

$(this).find('[type="checkbox‌​"]').each(function()

see following if it helps: 请参阅以下内容是否有帮助:

 <script type="text/javascript">

   $('.chkbxq').on('click', function (e) {

    alert('1'); // this alert is not firing 

    var checkchildgrid = $('#Gridparent').find(".k-detail-row").find('td.k-detail-cell').find('[type="checkbox‌​"]').prop('checked');
    alert(checkchildgrid);

    if ($(this).prop('checked')) {    
        checkchildgrid.prop('checked', 'checked');
    } else {
        checkchildgrid.prop('checked', false);
    }    
});        

i hope it helps. 我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM