File tree Expand file tree Collapse file tree 6 files changed +54
-7
lines changed Expand file tree Collapse file tree 6 files changed +54
-7
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace Griddly . Mvc
8+ {
9+ //TODO: Put GriddlySettings into GriddlyContext so that it doesn't need to be passed in separately
10+ public class EmptyGridMessageTemplateParams
11+ {
12+ public GriddlyResultPage ResultPage { get ; set ; }
13+ public GriddlySettings Settings { get ; set ; }
14+ }
15+ }
Original file line number Diff line number Diff line change 8787 <Link >Properties\CommonAssemblyInfo.cs</Link >
8888 </Compile >
8989 <Compile Include =" DynamicLinq.cs" />
90+ <Compile Include =" EmptyGridMessageTemplateParams.cs" />
9091 <Compile Include =" Exceptions\DapperGriddlyException.cs" />
9192 <Compile Include =" GriddlyContext.cs" />
9293 <Compile Include =" GriddlyCookieFilterValueProvider.cs" />
Original file line number Diff line number Diff line change @@ -83,6 +83,8 @@ public GriddlySettings()
8383 TableClassName = Css . TableDefault ;
8484 FooterTemplate = DefaultFooterTemplate ;
8585 HeaderTemplate = DefaultHeaderTemplate ;
86+ EmptyGridMessageTemplate = DefaultEmptyGridMessageTemplate ;
87+ EmptyGridMessage = DefaultEmptyGridMessage ;
8688 PageSize = DefaultPageSize ;
8789 InitialFilterMode = DefaultInitialFilterMode ;
8890 //AllowedFilterModes = DefaultAllowedFilterModes;
@@ -149,6 +151,11 @@ public static void ConfigureBootstrap4Defaults()
149151 public Func < GriddlyResultPage , object > FooterTemplate { get ; set ; }
150152 public Func < GriddlyResultPage , object > HeaderTemplate { get ; set ; }
151153
154+ public static Func < EmptyGridMessageTemplateParams , object > DefaultEmptyGridMessageTemplate { get ; set ; }
155+ public Func < EmptyGridMessageTemplateParams , object > EmptyGridMessageTemplate { get ; set ; }
156+ public static string DefaultEmptyGridMessage { get ; set ; }
157+ public string EmptyGridMessage { get ; set ; }
158+
152159 public Dictionary < string , Func < object , object > > RowIds { get ; protected set ; }
153160
154161 public virtual bool HasRowClickUrl
Original file line number Diff line number Diff line change 16961696 // https://github.com/programcsharp/griddly/issues/79
16971697 this . $element . find ( "tbody.data" ) . html ( html . children ( "tbody" ) . html ( ) ) ;
16981698
1699- var tfoot = this . $element . find ( "tfoot" ) ;
1699+ var tfoot = this . $element . find ( "tfoot.totals-tfoot" ) ;
1700+ if ( tfoot . length && html . children ( "tfoot.totals-tfoot" ) . length )
1701+ tfoot . replaceWith ( html . children ( "tfoot.totals-tfoot" ) ) ;
17001702
1701- if ( tfoot . length && html . children ( "tfoot" ) . length )
1702- tfoot . replaceWith ( html . children ( "tfoot" ) ) ;
1703+ var emptyMessage = this . $element . find ( "tfoot.empty-grid-message" ) ;
1704+ if ( emptyMessage . length && html . children ( "tfoot.empty-grid-message" ) . length )
1705+ emptyMessage . replaceWith ( html . children ( "tfoot.empty-grid-message" ) ) ;
17031706
17041707 var startRecord = this . options . pageNumber * this . options . pageSize ;
17051708
Original file line number Diff line number Diff line change 3939 {
4040 new GriddlyButton () { Text = " Dropdown Test" }
4141 .Add (new GriddlyButton () { Text = " UrlHelper Test" , Argument = Url .Action (" About" ) })
42- }
42+ },
43+ EmptyGridMessageTemplate = @< text >< div class = " alert alert-warning" > @item .Settings .EmptyGridMessage < / div >< / text > ,
44+ EmptyGridMessage = " Sorry, no records were found"
4345 }
4446 .Column(x => x.Id, filter: x => x.FilterBox(FilterDataType.Integer))
4547 .Column(x => x.Item, filter: x => x.FilterList(groupedList))
Original file line number Diff line number Diff line change 286286</tbody >
287287@if (settings .Columns .Any (x => x .SummaryFunction != null || x .SummaryValue != null ))
288288{
289- <tfoot >
289+ <tfoot class = " totals-tfoot " >
290290 <tr >
291291 @foreach ( GriddlyColumn column in settings .Columns )
292292 {
295295 </tr >
296296 </tfoot >
297297}
298+
299+ @if (settings .EmptyGridMessage != null ) {
300+ < tfoot class = " empty-grid-message" style = " @(Model.Total > 0 ? " display : none ;" : null)" >
301+ < tr >
302+ < td colspan = " @settings.Columns.Count" >
303+ @if (settings .EmptyGridMessageTemplate != null )
304+ {
305+ @settings .EmptyGridMessageTemplate (new EmptyGridMessageTemplateParams () { ResultPage = Model , Settings = settings })
306+ }
307+ else
308+ {
309+ @Model .Settings .EmptyGridMessage
310+ }
311+ < / td >
312+ < / tr >
313+ < / tfoot >
314+ }
315+
298316@if (isFirstRender )
299317{
300- @: </table >
301- @: </div >
318+ @: </table >
319+ @: </div >
320+
302321 <div class =" griddly-footer" >
303322 @if (settings .FooterTemplate == null || simple )
304323 {
You can’t perform that action at this time.
0 commit comments