How to select all checkboxes in Jquery using kendo header template?

I’m still a newb at coding and just started javascript about a month ago. Sorry for the poopy code.. Any help would me so much appreciated. Thanks..

So I have a kendo grid that I am using with razor and mvc. I will also need to bind the check mark and row changes so that it will update my drop down list (CustomerServiceCustomerCodeList)… but I will try to figure that part out when I get there… First more importantly I need to get the select all button working properly. My checkboxes are established with the client template and header template. I need to figure out how to select all the check marks in my header template part of the grid using jquery. The client template check individual boxes code works but not my check all. I’ve tried hundreds of different approaches and cant seem to get it working. Please help.

Kendo grid :

@using System.Windows
@using AITReporting.ReportService
@using EnvDTE
@using MyAITEntity
@using MyAITEntity.Quote
@using MyAITEntity.Shipment
@using MyAITEntity.User
@model IEnumerable<MyAITEntity.Shipment.ShipmentServiceLevel>
@{

    var userCustomerCode = HttpContext.Current.Session["ServiceLevelCustomerCode"];
}

@(Html.Kendo().Grid(Model)
    .Name("ServiceLevelGrid")
    .Reorderable(reorder => reorder.Columns(true))
    .Columns(columns =>
    {
        columns.Bound(s => s.IsSelected).Template(@<text></text>)
              .HeaderTemplate("<input type='checkbox' class='chkbx k-checkbox' id='selectAllCheck' />") 
              .ClientTemplate("<input type='checkbox' id='eachCheckbox' class='chkbxq k-checkbox' />")
                            .Sortable(false)
                            .Filterable(false)
    .Width(40);

        columns.Bound(s => s.ServiceLevelCode).Title("Code").Width(73);
        columns.Bound(s => s.ServiceLevelDescription);
        columns.Command(command => { command.Edit();}).Width(77);
    })
    .Sortable()
    .Scrollable()
    //.Editable(ed => ed.Mode(GridEditMode.InCell))
    .Selectable(s => s
        .Type(GridSelectionType.Row)
        .Mode(GridSelectionMode.Multiple)
    )
    .PersistSelection(false)
    .HtmlAttributes(new { style = "min-height:280px; height:280px;", id = "ServiceLevelGrid" })
    .DataSource(dataSource =>
    {
        dataSource
            .Ajax()
            //.Events(ev =>
            //{
            //    //ev.Change("CustomServiceLevel_DataSourceChange");
            //    //ev.Edit("CustomServiceLevelEdit");
            //    ev.Save("CustomServiceLevelSave");
            //    //ev.Sync("resyncChildGrid");
            //    //ev.RequestEnd("AddressBook_requestEnd");
            //})
            .Model(model =>
            {
                model.Id(s => s.ServiceLevelCode);
                model.Field(field => field.IsSelected).Editable(true);
                model.Field(field => field.ServiceLevelCode).Editable(false);
                model.Field(field => field.ServiceLevelCustomDescription).Editable(true);
            })
            .Batch(true)
            .Update(update =>
            {
                update.Action("ServiceLevelGrid_Update", "UserAccount", new {Area = "Management", CustomerCode = userCustomerCode});
                //update.Data("ServiceLevel_GetCustomList_Data");
            })
            .Read(read =>
            {
                read.Action("ServiceLevelGrid_Read", "UserAccount", new {Area = "Management", CustomerCode = userCustomerCode});
                //read.Data("ServiceLevel_GetCustomList_Data");
            });
    })
    )

@*.Events(ev => ev.DataBound("CustomServiceLevelGrid_DataBound"))*@

Here is my Jquery.

  debugger;
    //customer code dropdown list bind to grid 
    function ServiceLevel_GetCustomList_Data(event) {
        var customServiceCustomerCodeList = $("#CustomServiceCustomerCodeList").data("kendoDropDownList"),
            customServiceCustomerCodeList_DataItem = customServiceCustomerCodeList.dataItem(),
            customServiceCustomerCodeList_ItemValue = customServiceCustomerCodeList_DataItem["OrganizationCode"];

        var customServiceDataModel = {
            customerCode: customServiceCustomerCodeList_ItemValue
        }
        return customServiceDataModel;
    };



    //Checkbox grid 
    debugger;
    console.log();
    $('#ServiceLevelGrid').on("click", ".k-checkbox", function (e) {
        grdChkBoxClick(e);
    });

    function grdChkBoxClick(e) {
        var row = $(e.target).closest('tr');
        grdChkBoxUpdate(row);
    };

    };

    //individual check box select
    function grdChkBoxUpdate(row) {
        debugger;
        console.log();
        var grid = $("#ServiceLevelGrid").data("kendoGrid"),
            dataItem = grid.items().length > 0 ? grid.dataItem(row) : undefined,
            isItemChecked = ($("#eachCheckbox", row).prop("checked") === true);
        debugger;
        console.log();
        if (isItemChecked) {
            var isSelected = dataItem.IsSelected;
            dataItem.dirty = true;
            dataItem.IsSelected = true;
            console.log("isSelected: " + isSelected);
        } else {
            dataItem.dirty = true;
            dataItem.IsSelected = false;
        }
    }


    function checkAll(row) {
        $(".chkbxq").each(function () {
            debugger;
            console.log();
            // handle the checkbox logic
            // add logic to check if is checked or not and do proper handling based on that
                     $(this).attr('checked', row);

            // update dataItem to reflect changes.... (update model and dirty flag)
            grdChkBoxUpdate;

            var row = $(e.target).closest('tr');
            grdChkBoxUpdate(row);
           

        });
        }
    function checkAll(row) {
        $(".chkbxq").each(function () {
              debugger;
                      console.log();
              function sRow() {
                 var trLength = $("#ServiceLevelGrid .k - checkbox table tr").length;

                  if (trLength > 0) {
                      $("#ServiceLevelGrid .k - checkbox table tr").each(function(i) {
                          grdChkBoxUpdate(this);
                      });
                  }
              }
              var isSelected = $(".k-checkbox", "#ServiceLevelGrid thead").attr("aria-checked");
              if (isSelected !== "true") {
                  $(".k-checkbox", "#ServiceLevelGrid thead").click();
              }

                               $(this).attr('checked', row);

              var row = $(e.target).closest('tr');
              grdChkBoxUpdate(row);

                  });
    }