@@ -79,7 +79,10 @@ public static IHtmlContent RenderHtml<T>(this GridBuilder<T> grid)
7979 <table id=""{ grid . _name } "" class=""{ grid . _cssClass } "" style=""width:100%"">
8080 <thead>
8181 <tr>
82- { string . Join ( Environment . NewLine , grid . _columns . Select ( a => string . Format ( "<th>{0}</th>" , a . Title ) ) ) }
82+ { string . Join ( Environment . NewLine ,
83+ grid . _columns . Select ( a => grid . _selectEnable && grid . _selectItems == SelectItems . Checkbox && a . ClassName == "select-checkbox"
84+ ? $ "<th style=\" text-align:center\" ><input type=\" checkbox\" id=\" { grid . _name } _SelectAll\" ></th>"
85+ : string . Format ( "<th>{0}</th>" , a . Title ) ) ) }
8386 </tr>
8487 </thead>
8588 { tfoot }
@@ -271,6 +274,7 @@ public static IHtmlContent RenderScript<T>(this GridBuilder<T> grid)
271274 }});
272275 { ( string . IsNullOrEmpty ( grid . _captionTop ) ? string . Empty : string . Format ( "$('#{0}').append('<caption style=\" caption-side:top\" >{1}</caption>');" , grid . _name , grid . _captionTop ) ) }
273276 { ( string . IsNullOrEmpty ( grid . _captionBottom ) ? string . Empty : string . Format ( "$('#{0}').append('<caption style=\" caption-side:bottom\" >{1}</caption>');" , grid . _name , grid . _captionBottom ) ) }
277+ { grid . GetSelectionScript ( ) }
274278 </script>" ;
275279
276280 return new HtmlString ( script ) ;
@@ -285,5 +289,19 @@ private static string GetDataStr<T>(this GridBuilder<T> grid)
285289 { ( string . IsNullOrEmpty ( grid . _data ) ? string . Empty : string . Format ( "d.data = {0}()" , grid . _data ) ) }
286290 }}" ;
287291 }
292+
293+ private static string GetSelectionScript < T > ( this GridBuilder < T > grid )
294+ {
295+ return grid . _selectEnable && grid . _selectItems == SelectItems . Checkbox ?
296+ $@ "$(""#{ grid . _name } _SelectAll"").on( ""click"", function(e) {{
297+ var { grid . _name } DT = $(""#{ grid . _name } "").DataTable();
298+ if ($(this).is( "":checked"" )) {{
299+ { grid . _name } DT.rows().select();
300+ }}
301+ else {{
302+ { grid . _name } DT.rows().deselect();
303+ }}
304+ }});" : string . Empty ;
305+ }
288306 }
289307}
0 commit comments