How to Add custom html to Header in WebGrid

MyEvernote Link

Posted on March 30, 2013by mtryambake

How to make a MVC 3 Webgrid with checkbox column?
This article will show you a How to Add custom html to Header in WebGrid e.g. add a check box in webgrid header.

Some time you come across a situation where you have to add html element (checkbox) in webgrid header, consider a column with checkbox and you want to add checkbox in the header of same column.

Approach: In document.ready event find out webgrid header and replace it with html string.

  1. $(document).ready(function () {
  2. $('#gridContent table th').each(function () {
  3. if (this.innerHTML == "") {
  4. this.innerHTML = "<input type='checkbox' id='chkHeader' />";
  5. }
  6. });
  7. });

Application: If you have a checkbox column in webgrid and on clicking of header checkbox all checkbox in column will be checked.

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. $('#gridContent table th').each(function () {
  4. if (this.innerHTML == "") {
  5. this.innerHTML = "<input type='checkbox' id='chkHeader' />";
  6. }
  7. });
  8. $('#gridContent table th input:checkbox').click(function (e) {
  9. var table = $(e.target).closest('table');
  10. $('td input:checkbox', table).attr('checked', e.target.checked);
  11. });
  12. });
  13.  
  14. </script>
  15. ========================================================================================================
  1. for reference
  1. ========================================================================================================
  1. $(function () {
  2. $('.gridTable thead tr th:first').html(
  3. $('<input/>', {
  4. type: 'checkbox',
  5. click: function () {
  6. var checkboxes = $(this).closest('table').find('tbody tr td input[type="checkbox"]');
  7. checkboxes.prop('checked', $(this).is(':checked'));
  8. }
  9. })
  10. );
  11. });

[webgrid] – header - (How to Add custom html to Header in WebGrid)的更多相关文章

  1. Add custom and listview web part to a page in wiki page using powershell

    As we know, Adding list view web part is different from custom web part using powershell, what's mor ...

  2. How To Add Custom Build Steps and Commands To setup.py

    转自:https://jichu4n.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy/ A setup.py scrip ...

  3. Add custom daemon on Linux System

    Ubuntu add custom service(daemon) Task 需要在系统启动的时候自动启动一个服务(后台程序),在系统关闭的时候关闭服务. 比如在部署某个应用之前,需要将某个任务设置成 ...

  4. RestTemplate发送请求并携带header信息 RestTemplate post json格式带header信息

    原文地址:  http://www.cnblogs.com/hujunzheng/p/6018505.html RestTemplate发送请求并携带header信息   v1.使用restTempl ...

  5. Add custom field in Material Master

    1.Add fields in the Append Structure of table MARA. 2.Configure SPRO IMG -> Logistics General -&g ...

  6. grafana add custom dashboard

    grafana-dashboard-json prometheus-operator helm 中的grafana dashboard 扩展的时候,需要转换下载(https://grafana.com ...

  7. [webgrid] – selecterow - (Get Selected Row from ASP.NET MVC 3 WebGrid)

    Get Selected Row from ASP.NET MVC 3 WebGrid Abstract: The following article demonstrates how to get ...

  8. Umbrella Header for Module Bolts does not include header &#39;XXXXXX.h&#39;?

    在我们引入第三方Framwork时.有时会出现如标题的警告提示? 怎样解决? Framework 将在下面文件夹下创建一个Module/,并创建一个module.modulemap文件 waterma ...

  9. 开发Angular库的简单指导(译)

    1. 最近工作上用到Angular,需要查阅一些英文资料,虽然英文非常烂,但是种种原因又不得不硬着头皮上,只是每次看英文都很费力,因此决定将一些比较重要的特别是需要反复阅读的资料翻译一下,以节约再次阅 ...

随机推荐

  1. Fiddler+Jmeter+断言详细教程

    一.Fiddler抓包工具的配置和使用 在编写网关自动化脚本之前,得先学会如何抓包,这里以Fiddler为例.会抓包的同学可以跳过这一步,当然看看也是没坏处的-- 局域网络配置 将要进行抓包的手机与电 ...

  2. 使用iframe 或frameset框架退出不成功

    iframe .frameset框架有时登录界面加载在框架当中,但我们想直接到登录界面,这时我们可以使用js来实现.if(window!=top) { top.location.href=locati ...

  3. Yii2事务

    今天写到发券,发现没加事务,于是学习了下 事务: 是指作为单个逻辑工作单元执行的一系列操作,要么完全地执行,要么完全地不执行. 事务处理可以确保除非事务性单元内的所有操作都成功完成,否则不会永久更新面 ...

  4. 用 perl 统计 fasta 文件序列的总长

    #!/usr/bin/perl -w use strict; die "Usage: $0 <file>\n" unless (@ARGV == 1); my $lin ...

  5. Thinking in java学习笔记之finalize

    finalize:一旦垃圾回收器准备好释放对象占用的存储空间,将首先调用其finalize()方法,并且在下次垃圾回收动作发生时,才会真正回收对象占用的内存,所以可用此作为对象终结条件的验证.注意的三 ...

  6. 77.Android之代码混淆

    转载:http://www.jianshu.com/p/7436a1a32891 简介 作为Android开发者,如果你不想开源你的应用,那么在应用发布前,就需要对代码进行混淆处理,从而让我们代码即使 ...

  7. [学习笔记]tarjan求割边

    上午打模拟赛的时候想出了第三题题解,可是我不会求割边只能暴力判割边了QAQ 所以,本文介绍求割边(又称桥). 的定义同求有向图强连通分量. 枚举当前点的所有邻接点: 1.如果某个邻接点未被访问过,则访 ...

  8. Java并发和多线程(一)基础知识

    1.java线程状态 Java中的线程可以处于下列状态之一: NEW: 至今尚未启动的线程处于这种状态. RUNNABLE: 正在 Java 虚拟机中执行的线程处于这种状态. BLOCKED: 受阻塞 ...

  9. BZOJ 1029 建筑抢修 贪心+堆

    又搞了一晚上OI,编了两道BZOJ和几道NOI题库,临走之前写两篇感想 noip越来越近了,韩大和clove爷已经开始停课虐我们了... 1029: [JSOI2007]建筑抢修 Time Limit ...

  10. DedeCMS顽固木马后门专杀工具V2.0实现方式研究

    catalog . 安装及使用方式 . 检查DEDECMS是否为最新版本 . 检查默认安装(install)目录是否存在 . 检查默认后台目录(dede)是否存在 . 检查DedeCMS会员中心是否关 ...