javascript - Kendo -MVC ListView - How to Get Checkbox state(checked or not) on selected row -
i trying catch checkboxes state(checked or not) on every click checkboxes on specific row.i can able id value of row clicked cannot retrieve checkbox state properly,it returns false of time(even if it's checked).at end planning edit records according checkboxes state.
-on page load status of checkboxes set according model value.
html(razor)
@(html.kendo().listview<ais.ui.webservice.proxy.dsrvallservice.newsitem>() .name("listview") .events(e => e.change("changefunc")) .tagname("div") .selectable() .clienttemplateid("template") .autobind(true) .datasource(datasource => datasource .model(model => model.id("id")) .pagesize(5) //...some options
kendo template:
<div class="container-fluid" style="padding-right:0px;border-bottom:1px solid \\#d4d4d4"> <div class=" col-sm-4" style="padding-top: 2px; min-height: 35px;margin-right:-1px; border-right: 1px solid rgb(212, 212, 212)"> <span class="bold" style="color: black;">#:title#</span> </div> <div id="typefield" class="col-sm-4" > @if(@viewbag.type=="all") { <label class="checkbox-inline"> <input type="checkbox" id="webcheckbox" value="web" checked = "checked" /> <span style="vertical-align:middle">web</span> </label> <label class="checkbox-inline"> <input type="checkbox" id="ambulancecheckbox" value="client" checked="checked" /> <span>ambulance client</span> </label> } else{ <label class="checkbox-inline"> <input type="checkbox" id="webcheckbox" value="web" /> @if (@viewbag.type == "web") { <input type="checkbox" id="webcheckbox" value="web" checked="checked" /> } <span style="vertical-align:middle">web</span> </label> <label class="checkbox-inline"> <input type="checkbox" id="ambulancecheckbox" value="client" /> @if (@viewbag.type == "client") { <input type="checkbox" id="ambulancecheckbox" value="client" checked="checked" /> } <span>ambulance client</span> </label> } </div> <div class="col-sm-2 pull-right " style="padding-right:0px;" > @* <a class="btn pull-right" href="\\#"><span class="k-icon k-delete"></span></a>*@ <a id="deletebutton" class="btn-old btn-default pull-right k-button-icontext k-delete-button" ><span class="k-icon k-delete"></span></a> <a class="btn-old btn-default pull-right" onclick="openannouncement('#:id#')"><span class="k-icon k-edit"></span></a> @* <button id="opencasedetails" class="btn pull-right btn-primary" onclick="openannouncement('#:id#')" type="button" >edit</button> <button id="deletecasedetails" class="btn pull-right btn-primary" onclick="deleteannouncement('#:id#')" type="button" >delete</button>*@ </div> </div> </script>
js:
<script > function changefunc(e) { var index = this.select().index(), dataitem = this.datasource.view()[index]; //id of selected row's record var id = dataitem.id; //the section trying retrieve checkboxes state on click //failed!!! var isweb = $('#ambulancecheckbox').is(':checked'); var isclient = $('#webcheckbox').is(':checked'); //also failed // var isweb = $('#ambulancecheckbox').prop('checked') // var isclient = $('#webcheckbox').prop(':checked'); } </script>
giving id checkbox inside template not idea because there multiple input elements such id.
instead suggest giving class.
once give class can find checkbox within selected row , state.
e.g.
function changefunc(e) { alert(this.select().find(".mycheckbox").is(":checked")); ... }
Comments
Post a Comment