kendo listView with checkbox along with select all

2019-04-12 10:52发布

I am new to kendo UI implementation and am looking for a way to create a listview with checkbox, the very first checkbox being All Option to select all items in listview if it is checked. I have created a template that allows me to add checkbox to the items, But i need to add a ALL checkbox on top of all the data. this is what i have worked in so far, Below (screenshot) is what i would like to achieve.

Here is my template:

<script type="text/x-kendo-tmpl" id="myTemplate">
    <div class="item click" data="${ProductID}">
        <input type="checkbox" class="click" />
        <span class="checkbox">#:ProductName#</span>
    </div>
</script>

http://jsfiddle.net/Archie/w6jsZ/

LIstview with checkboxes

2条回答
2楼-- · 2019-04-12 11:37

I think you are looking for a treeview. See the demo from kendo

http://demos.kendoui.com/web/treeview/checkboxes.html

查看更多
Luminary・发光体
3楼-- · 2019-04-12 11:45

Your code seem like this: http://jsfiddle.net/Archie/w6jsZ/

<div style="width:250px;height:350px;overflow-y:scroll;">
    <div>
        <input type="checkbox" id="checkall" class="click" />
        <span class="checkbox">All</span>
    </div>
    <div id="listView" class="k-listview" >
    </div>
</div>
<script type="text/x-kendo-tmpl" id="myTemplate">

    <div class="item click" data="${ProductID}">
        <input type="checkbox" class="click" />
        <span class="checkbox">#:ProductName#</span>
    </div>
</script>

 $(document).ready(function () {

     function checkboxEventBinding()
     {
         $('#checkall').bind('click',function(e){
             if(this.checked)
             {
                 $('.item.click input').attr('checked','checked');
             }
             else
             {
                 $('.item.click input').removeAttr('checked');
             }

         })
     }
     var dataSource = new kendo.data.DataSource({
                  transport: {
                      read: {
                         url: "http://demos.kendoui.com/service/Products",
                            dataType: "jsonp"
                      }
                 }
                });
          $("#listView").kendoListView({
                dataSource: dataSource,
                template: kendo.template($("#myTemplate").html()),
              headertemplate:"<div class='item click' id='headerTemp' data='*'>       <input type='checkbox' class='click' /><span class='checkbox'>All</span></div>",
              dataBound: function(e) {
         checkboxEventBinding();
     }
            });


        });
  1. Insert a check-box (for check all) before kendo-list template
  2. When user lick on Check-all Input, others input will be checked too.
  3. Rebind your event after kendo-list rebind data.

//UPDATE

To get check-box values:

Make sure your list was wrapped by "form" tag

<form id="frmChk">
    <div id="listView" class="k-listview" >
    </div>
</form>

All input tag have the same name

<script type="text/x-kendo-tmpl" id="myTemplate">
    <div class="item click"  data="${ProductID}">
        <input type="checkbox" name="chkValue" value="${ProductID}"  class="click" />
        <span class="checkbox">#:ProductName#</span>
    </div>
</script>

Go get values you can use serialize method of jquery:

<script>
    function getCheckedBoxValue()
    {
        $("#frmChk").serialize(); 
    }
</script>

If your input :

<input type="checkbox" name="chkValue" value="Ikura1" class="click" />
<input type="checkbox" name="chkValue" value="Ikura2" class="click" />
<input type="checkbox" name="chkValue" value="Ikura3" class="click" />

When you call getCheckedBoxValue, result will like this:

chkValue=Ikura1,Ikura2,Ikura3
查看更多
登录 后发表回答