Archana David
Archana David

Reputation: 1384

kendo listView with checkbox along with select all checkbox option

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

_http://jsfiddle.net/Archie/w6jsZ/

LIstview with checkboxes

Upvotes: 2

Views: 22920

Answers (2)

Hung Doan
Hung Doan

Reputation: 1167

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 the kendo-list template
  2. When the user clicks on Check-all Input, other input will be checked too.
  3. Rebind your event after the kendo-list rebind data.

//UPDATE

To get check-box values:

Make sure your list was wrapped by a "form" tag

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

All input tags 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 the values. You can use serialize method of jQuery:

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

If your input is

<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, the result will like this:

chkValue=Ikura1,Ikura2,Ikura3

Upvotes: 6

Roland
Roland

Reputation: 97

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

Checkboxes

Upvotes: 2

Related Questions