[webgrid] – header - (How to Add custom html to Header in WebGrid)

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.

     $(document).ready(function () {
         $(‘#gridContent table th‘).each(function () {
             if (this.innerHTML == "") {
                 this.innerHTML = "<input type=‘checkbox‘ id=‘chkHeader‘  />";
             }
         });
     });

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

<script type="text/javascript">
     $(document).ready(function () {
         $(‘#gridContent table th‘).each(function () {
             if (this.innerHTML == "") {
                 this.innerHTML = "<input type=‘checkbox‘ id=‘chkHeader‘  />";
             }
         });
         $(‘#gridContent table th input:checkbox‘).click(function (e) {
             var table = $(e.target).closest(‘table‘);
             $(‘td input:checkbox‘, table).attr(‘checked‘, e.target.checked);
         });
     });

</script>
========================================================================================================
                         for reference
========================================================================================================
$(function () {
    $(‘.gridTable thead tr th:first‘).html(
        $(‘<input/>‘, {
            type: ‘checkbox‘,
            click: function () {
                var checkboxes = $(this).closest(‘table‘).find(‘tbody tr td input[type="checkbox"]‘);
                checkboxes.prop(‘checked‘, $(this).is(‘:checked‘));
            }
        })
    );
});
时间: 2024-08-10 23:30:18

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

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

在我们引入第三方Framwork时,有时会出现如标题的警告提示? 如何解决? Framework 将在以下目录下创建一个Module/,并创建一个module.modulemap文件 我们需要在module.modulemap中,增加一个header文件(XXXXXXX.h),以达到显示Module的功能.下面是如何在module.modulemap文件添加header文件 的方法: framework module UUAP { umbrella header "UUAP.h" ex

Add Custom Tab in Detail screen for MIGO Transaction

1.Run Tcode se19 2.create enhancement and click on classic badi radio button 3.Enter badi name MB_MIGO_BADI and click on button create 4. give you Implementation Name 5. Click method of interface .it will ask you to create the enhancement implementat

[webgrid] &ndash; 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 the selected row from the ASP.NET MVC 3 WebGrid and what to do to display data. Every website has to display data and every website has a Grid control

基于jQuery HTML5添加到购物车代码

基于jQuery HTML5添加到购物车代码.这是一款支持选择颜色跟样式的添加购物车代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <header> <h1>Quick Add to Cart</h1> </header> <a href="#0" class="cd-cart"> <span>0</span> </a> <ul class

android okhttp和webview session共享

public static OkHttpClient get(Context context){ OkHttpClient.Builder builder = new OkHttpClient.Builder() .cookieJar(new WebViewCookieHandler(context)) .connectTimeout(15, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .readTimeout(30, TimeUn

[转]Writing Custom Middleware in ASP.NET Core 1.0

本文转自:https://www.exceptionnotfound.net/writing-custom-middleware-in-asp-net-core-1-0/ One of the new features from ASP.NET Core 1.0 is the idea of Middleware. Middleware are components of an application that examine the requests responses coming in t

Writing a Reusable Custom Control in WPF

In my previous post, I have already defined how you can inherit from an existing control and define your own reusable chunk. The reusable XAML code that I have defined there is actually a composition of one of more existing elements in a common desig

Volley和OkHttp并用时导致http header数据被覆盖的bug

问题出在BasicNetwork的performRequest()方法中,出问题的代码如下: public NetworkResponse performRequest(Request<?> request) throws VolleyError { long requestStart = SystemClock.elapsedRealtime(); while (true) { HttpResponse httpResponse = null; byte[] responseContents

delphi xe6 android ListView增加 Header或Footer 的方法

var  Item1: TListViewItem;begin    Item1 := ListView1.Items.Add;    Item1.Purpose:=TListItemPurpose.Header;//    Item1.Purpose:=TListItemPurpose.Footer;    Item1.text:=' xxxx';//Header或Footer显示的内容end; delphi xe6 android ListView增加 Header或Footer 的方法,布