This is a migrated thread and some comments may be shown as answers.

Checkbox state in grid paging( prev/next)

1 Answer 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mahesh
Top achievements
Rank 1
Mahesh asked on 17 Apr 2012, 02:50 PM
Hi

I have a column  with checkboxes in my telerik grid. If I checked the checkboxes in first page then go to the next page, the previous page checkboxes getting unchecked. Is there any checkbox state to maintain the checkboxes as checked while clicking on prev/next in telerik grid. Please help me out.

Thanks
Mahesh

1 Answer, 1 is accepted

Sort by
0
Mahesh
Top achievements
Rank 1
answered on 18 Apr 2012, 10:31 AM
I found the solution for that,
I am putting the complete code here. You can use this code for checkbox state.

@model IEnumerable<ClaimCorrection.Models.ClaimCorrectionTable>
      <script type="text/javascript">
        var selectedIds = [];

        $(document).ready(function () {
            //wire up checkboxes.
            $('#GridClaimCorrection :checkbox').live('change', function (e) {
                //alert('checked');
                var $check = $(this);
               // console.log($check);
                if ($check.is(':checked')) {
                    //add id to selectedIds.
                    // alert('id added');
                    selectedIds.push($check.val());

                }
                else {
                    //remove id from selectedIds.
                    selectedIds = $.grep(selectedIds, function (item, index) {
                        return item != $check.val();
                    });                    
                }
            });
        });

         function onDataBound(e) {
            //restore selected checkboxes.
            $('#GridClaimCorrection :checkbox').each(function () {
                //alert('state');
                //set checked based on if current checkbox's value is in selectedIds.
                
                $(this).attr('checked', jQuery.inArray($(this).val(), selectedIds) > -1);
            });
        }

        //-----------------------------------------------------------------------------------------------------------------------------------
    </script>
 

@(Html.Telerik().Grid(Model)

            .Name("GridClaimCorrection")
            .ClientEvents(events => events.OnDataBound("onDataBound"))
            .Columns(columns =>
            {
                columns.Bound(o => o.Coverage)
                    .Template(
                    @<text>
                    <input name="checkedRecords" class = "checkedClass" type="checkbox"  value="@item.Coverage " title="checkedRecords" />
                    </text>).ClientTemplate("<# if (InvoiceNumber!=null) { #>"+"<input name='checkedRecords'   class = 'first' type='checkbox' value='@item.Coverage' title='checkedRecords' />"+   " <# } else { #>" +
                                                                       "<div></div>" +
                                                                         " <# } #>")
                    .Title("Coverage")
                    .Width(76)                    
                    .HtmlAttributes(new { style = "text-align:center" });
                    
                     columns.Bound(o => o.Regenerate)
                         .Template(
                         @<text>
                    <input name="checkedRecords" class = "checkedClass" type="checkbox"  value="@item.Regenerate " title="checkedRecords" />
                    </text>).ClientTemplate("<input name='checkedRecords1'  class = 'first' type='checkbox'  value='<#= ClaimNumber #>' title='checkedRecords' />")
                         .Title("Regenerate")
                         .HtmlAttributes(new { style = "text-align:center" });


                     columns.Bound(o => o.InvoiceNumber);
                     columns.Bound(o => o.ClaimNumber);
                     columns.Bound(o => o.CoverageType);
                     columns.Bound(o => o.PlanType);
                     columns.Bound(o => o.CenterId);
                     columns.Bound(o => o.PatientId);
                     columns.Bound(o => o.PatientName);
                     columns.Bound(o => o.BillingMonth);
                     columns.Bound(o => o.DOS).Format("{0:MM/dd/yyyy}");
            }

                                    )
                                    .Resizable(resize => resize.Columns(true))
                                    .Reorderable(reorder => reorder.Columns(true))
                                       .DataBinding(dataBinding => dataBinding.Ajax().Select("IndexAjax", "ClaimCorrection"))
                                       .Scrollable(scrolling => scrolling.Enabled(true))
                                       .Sortable(sorting => sorting.Enabled(true))
                                       .ClientEvents(e => e.OnLoad("onLoad").OnDataBinding("dataBinding"))
                                       .Pageable(paging => paging.PageSize(5).Style(GridPagerStyles.NextPrevious).Position(GridPagerPosition.Both)

                                     )
                                 )
Tags
General Discussions
Asked by
Mahesh
Top achievements
Rank 1
Answers by
Mahesh
Top achievements
Rank 1
Share this question
or