Exemple #1
0
 /// <summary>
 /// Render datatable script for prepared grid builder
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="gridBuilder"></param>
 /// <returns></returns>
 public static MvcHtmlString Render <T>(this GridBuilder <T> gridBuilder)
 {
     var html = $@"
             <table id=""{gridBuilder._name}"" class=""{gridBuilder._cssClass}"" style=""width:100%"">
                 <thead>
                     <tr>
                         {string.Join(Environment.NewLine, gridBuilder._columns.Select(a => string.Format("<th>{0}</th>", a.Title)))}
                     </tr>
                 </thead>
             </table>
             <script>
             $(document).ready(function () {{
                 $('#{gridBuilder._name}').DataTable( {{
                     processing:true,
                     serverSide:{gridBuilder._serverSide.ToLowString()},
                     fixedColumns: {{ 
                         leftColumns: {gridBuilder._leftColumns},
                         rightColumns: {gridBuilder._rightColumns}
                     }},
                     order:[],
                     orderdering: {gridBuilder._ordering.ToLowString()},
                     searching: {gridBuilder._searching.ToLowString()},
                     paging: {gridBuilder._paging.ToLowString()},
                     language: {{
                         'url': '{gridBuilder._langUrl}'
                     }},
                     ajax: {{
                         url: ""{gridBuilder._url}"",
                         type: ""{gridBuilder._method}"",
                         data: {gridBuilder.GetDataStr()}
                     }},
                     columns: [{string.Join(", ", gridBuilder._columns.Select(a => $@"{{ 
                         'data': '{a.Data}',
                         'orderable': {a.Orderable.ToLowString()},
                         'searchable': {a.Searchable.ToLowString()},
                         'className': '{a.ClassName}',
                         'visible': {a.Visible.ToLowString()},
                         'width': '{a.Width}%',
                             {(string.IsNullOrEmpty(a.Render) ? string.Empty : $"'render': function(data, type, row, meta) {{ if (data == null) {{ return ''; }} else {{ return {a.Render}; }} }}")}
                     }}"))}]
                 }});
             }});
             {(string.IsNullOrEmpty(gridBuilder._captionTop) ? string.Empty : string.Format("$('#{0}').append('<caption style=\"caption-side:top\">{1}</caption>');", gridBuilder._name, gridBuilder._captionTop))}
Exemple #2
0
        /// <summary>
        /// Render datatable script for prepared grid builder
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="gridBuilder"></param>
        /// <returns></returns>
        public static MvcHtmlString Render <T>(this GridBuilder <T> gridBuilder)
        {
            var tfoot = gridBuilder._columnSearching ?
                        $@"<tfoot>
                            <tr>
                                {string.Join(Environment.NewLine, gridBuilder._columns.Select(a => string.Format("<th>{0}</th>", a.Searchable ? $"<input type=\"{((a.Type == typeof(DateTime?) || a.Type == typeof(DateTime)) && gridBuilder._serverSide ? "date" : "text")}\" style=\"width:100%\" placeholder=\"{a.Title}\" class=\"{gridBuilder._columnSearchingCss}\" />" : "")))}
                            </tr>
                        </tfoot>"
                        : string.Empty;

            var tfootInit = gridBuilder._columnSearching ?
                            $@"initComplete: function () {{
                                        this.api().columns().every(function() {{
                                            var that = this;
                                            $('input', this.footer()).on('keyup change clear', function () {{
                                                if (that.search() !== this.value) {{
                                                    that
                                                        .search(this.value)
                                                        .draw();
                                                }}
                                            }});
                                        }});
                                    }},"
                                    : string.Empty;
            var html = $@"
                    <table id=""{gridBuilder._name}"" class=""{gridBuilder._cssClass}"" style=""width:100%"">
                        <thead>
                            <tr>
                                {string.Join(Environment.NewLine, gridBuilder._columns.Select(a => string.Format("<th>{0}</th>", a.Title)))}
                            </tr>
                        </thead>
                        {tfoot}
                    </table>
                    <script>
                    $(document).ready(function () {{
                        $('#{gridBuilder._name}').DataTable( {{
                            {tfootInit}
                            processing:true,
                            serverSide:{gridBuilder._serverSide.ToLowString()},
                            fixedColumns: {{ 
                                leftColumns: {gridBuilder._leftColumns},
                                rightColumns: {gridBuilder._rightColumns}
                            }},
                            order:[],
                            ordering: {gridBuilder._ordering.ToLowString()},
                            searching: {gridBuilder._searching.ToLowString()},
                            paging: {gridBuilder._paging.ToLowString()},
                            language: {{
                                'url': '{gridBuilder._langUrl}'
                            }},
                            ajax: {{
                                url: ""{gridBuilder._url}"",
                                type: ""{gridBuilder._method}"",
                                data: {gridBuilder.GetDataStr()}
                            }},
                            columns: [{string.Join(", ", gridBuilder._columns.Select(a => $@"{{ 
                                'data': '{a.Data}',
                                'orderable': {a.Orderable.ToLowString()},
                                'searchable': {a.Searchable.ToLowString()},
                                'className': '{a.ClassName}',
                                'visible': {a.Visible.ToLowString()},
                                'width': '{a.Width}%',
                                    {(string.IsNullOrEmpty(a.Render) ? string.Empty : $"'render': function(data, type, row, meta) {{ if (data == null) {{ return ''; }} else {{ return {a.Render}; }} }}")}
                            }}"))}]
                        }});
                    }});
                    {(string.IsNullOrEmpty(gridBuilder._captionTop) ? string.Empty : string.Format("$('#{0}').append('<caption style=\"caption-side:top\">{1}</caption>');", gridBuilder._name, gridBuilder._captionTop))}
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnBuilder{T}"/> class.
 /// </summary>
 /// <param name="grid">The grid.</param>
 public ColumnBuilder(GridBuilder <T> grid)
 {
     _grid = grid;
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterBuilder{T}"/> class.
 /// </summary>
 /// <param name="grid">The grid.</param>
 public FilterBuilder(GridBuilder <T> grid)
 {
     _grid = grid;
 }