Ejemplo n.º 1
0
        /// <summary>
        /// Override Render base method to avoid creation of <span> elements surrounding the controls output
        /// </summary>
        /// <param name="output"></param>
        protected override void Render(HtmlTextWriter output)
        {
            var html = new StringBuilder();

            // Create table which will hold grid
            html.AppendLine("<table id=\"" + ID + "\"></table>");

            // Toolbar search section
            if (ToolbarSearchEnabled)
            {
                html.AppendLine("<table id=\"" + ID + "Search\"></table>");
            }

            // Pager section
            if (PagingEnabled)
            {
                html.AppendLine("<div id=\"" + ID + "Pager\"></div>");
            }

            // Start javascript
            html.AppendLine("<script type=\"text/javascript\">");
            html.AppendLine("$(document).ready(function(){");
            html.AppendLine("jQuery('#" + ID + "').jqGrid({");

            // Url
            html.AppendFormat("url: '{0}',", Url).AppendLine();

            // Pager
            if (PagingEnabled)
            {
                html.AppendLine("pager: '#" + ID + "Pager',");
            }

            // Title
            if (!string.IsNullOrWhiteSpace(Title))
            {
                html.AppendFormat("caption: '{0}',", Title).AppendLine();
            }

            // Width
            if (Width.HasValue)
            {
                html.AppendFormat("width: {0},", Width).AppendLine();
            }
            else
            {
                html.AppendFormat("autowidth: true,").AppendLine();
            }

            // Height
            if (!(VirtualScroll.HasValue && VirtualScroll.Value && !Height.HasValue))
            {
                html.AppendFormat("height: {0},", Height.HasValue ? Height.ToString() : "'100%'").AppendLine();
            }

            // Row number
            if (RowNumber.HasValue)
            {
                html.AppendFormat("rowNum: {0},", RowNumber).AppendLine();
            }

            // View record
            if (ViewRecords.HasValue)
            {
                html.AppendFormat("viewrecords: {0},", ViewRecords.ToString().ToLower()).AppendLine();
            }

            // Virtual scroll
            if (VirtualScroll.HasValue && VirtualScroll.Value)
            {
                html.AppendLine("scroll: 1,");
            }

            // Scroll offset
            if (ScrollOffset.HasValue)
            {
                html.AppendFormat("scrollOffset: {0},", ScrollOffset.Value).AppendLine();
            }

            // On select row
            if (!string.IsNullOrWhiteSpace(OnSelectRow))
            {
                html.AppendFormat("onSelectRow: {0},", OnSelectRow).AppendLine();
            }

            // Column names
            html.AppendFormat("colNames:[{0}],", string.Join(",", Columns.Select(x => "'" + x.HeaderText + "'"))).AppendLine();

            // Column model
            html.AppendFormat("colModel:[{0}],", string.Join(",", Columns.Select(x =>
                                                                                 "{name:'" + x.DataField + "'" +
                                                                                 ", index:'" + x.DataField + "'" +
                                                                                 ", title: false" +
                                                                                 (x.Width.HasValue ? ", width:" + x.Width : "") +
                                                                                 (x.SearchOptions != null && x.SearchOptions.Any() ? ", stype: 'select'" : "") +
                                                                                 (x.SearchOptions != null && x.SearchOptions.Any() ? ", searchoptions: { value: ':;" + string.Join(";", x.SearchOptions.Select(y => y.Value + ":" + y.Text)) + "'}" : "") +
                                                                                 (!(x.SearchOptions != null && x.SearchOptions.Any()) && x.DatePicker ? ", searchoptions: { dataInit:function(el){$(el).datepicker({changeYear:true, onSelect: function() {var sgrid = $('#" + ID + "')[0]; sgrid.triggerToolbar();},dateFormat:'dd-mm-yy'});} }" : "") +
                                                                                 "}"
                                                                                 ))).AppendLine();

            // Fixed settings
            html.AppendLine(@"
                                serializeGridData: function (postData) {
                                    return JSON.stringify({ jqGridRequest : postData });
                                },
                                jsonReader : { 
                                    root: 'd.rows', 
                                    page: 'd.page', 
                                    total: 'd.total', 
                                    records: 'd.records', 
                                    repeatitems: false, 
                                    id: 'id',
                                    userdata: 'userdata',
                                    subgrid: { 
                                        root:'rows', 
                                        repeatitems: true, 
                                        cell:'cell' 
                                    } 
                                },
                                prmNames: {
                                    page: 'PageIndex',
                                    rows: 'PageSize', 
                                    sort: 'SortIndex', 
                                    order: 'SortOrder', 
                                    search: 'IsSearch'
                                },
                                ajaxGridOptions: {
                                    contentType: 'application/json; charset=utf-8'
                                },
                                datatype: 'json',
                                mtype: 'POST'");

            // End javascript
            html.AppendLine("});");

            // Toolbar search
            if (ToolbarSearchEnabled)
            {
                html.AppendLine("jQuery('#" + ID + "').jqGrid('filterToolbar', {stringResult:true, searchOnEnter:false});");
            }

            html.AppendLine("});");
            html.AppendLine("</script>");

            output.Write(html.ToString());
        }
Ejemplo n.º 2
0
 public HomeController()
 {
     records = new ViewRecords();
     dbh     = new RecordContext();
     funx    = new FileFormat();
 }
Ejemplo n.º 3
0
        public void Execute(object parameter)
        {
            var popup = new ViewRecords();

            popup.Show();
        }