Пример #1
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderContainerAsync(GridRecordData model)
        {
            ScriptBuilder sb = new ScriptBuilder();

            GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(model.GridDef);

            // render record
            string tr = await GridDisplayComponent.RenderRecordHTMLAsync(HtmlHelper, model.GridDef, dictInfo, model.FieldPrefix, model.Data, 0, 0, false);

            GridRecordResult result = new GridRecordResult {
                TR         = tr,
                StaticData = model.Data,
            };

            sb.Append(Utility.JsonSerialize(result));

            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderContainerAsync(GridPartialData model)
        {
            ScriptBuilder sb = new ScriptBuilder();

            GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(model.GridDef);

            // render all records
            string data = await GridDisplayComponent.RenderTableHTML(HtmlHelper, model.GridDef, model.Data, model.StaticData, dictInfo, model.FieldPrefix, true, model.Skip, model.Take);

            data += Manager.ScriptManager.RenderEndofPageScripts();// portions generated by components

            int pages    = 0;
            int page     = 0;
            int pageSize = model.Take;

            if (model.Data.Total > 0)
            {
                if (model.Take == 0)
                {
                    pages    = 1;
                    pageSize = 0;
                }
                else
                {
                    pages = Math.Max(1, model.Data.Total / model.Take + (model.Data.Total % model.Take == 0 ? 0 : 1));
                    page  = Math.Max(model.Skip / model.Take, 0);
                }
            }

            GridPartialResult result = new GridPartialResult {
                Records  = model.Data.Total,
                TBody    = data,
                Pages    = pages,
                Page     = page,
                PageSize = pageSize,
            };

            sb.Append(Utility.JsonSerialize(result));

            return(sb.ToString());
        }
Пример #3
0
        public static async Task SaveSettingsAsync(GridPartialData gridData)
        {
            // save the current sort order and page size
            if (gridData.GridDef.SettingsModuleGuid != null && gridData.GridDef.SettingsModuleGuid != Guid.Empty)
            {
                GridLoadSave.GridSavedSettings gridSavedSettings = GridLoadSave.LoadModuleSettings((Guid)gridData.GridDef.SettingsModuleGuid);
                gridSavedSettings.PageSize = gridData.Take;
                if (gridData.Take == 0)
                {
                    gridSavedSettings.CurrentPage = 1;
                }
                else
                {
                    gridSavedSettings.CurrentPage = Math.Max(1, gridData.Skip / gridData.Take + 1);
                }
                foreach (GridDefinition.ColumnInfo col in gridSavedSettings.Columns.Values)
                {
                    col.Sort = GridDefinition.SortBy.NotSpecified;
                }
                if (gridData.Sorts != null)
                {
                    foreach (var sortCol in gridData.Sorts)
                    {
                        GridDefinition.SortBy sortDir = (sortCol.Order == DataProviderSortInfo.SortDirection.Ascending) ? GridDefinition.SortBy.Ascending : GridDefinition.SortBy.Descending;
                        if (gridSavedSettings.Columns.ContainsKey(sortCol.Field))
                        {
                            gridSavedSettings.Columns[sortCol.Field].Sort = sortDir;
                        }
                        else
                        {
                            gridSavedSettings.Columns.Add(sortCol.Field, new GridDefinition.ColumnInfo {
                                Sort = sortDir
                            });
                        }
                    }
                }
                GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(gridData.GridDef);

                foreach (GridDefinition.ColumnInfo col in gridSavedSettings.Columns.Values)
                {
                    col.FilterOperator = null;
                    col.FilterValue    = null;
                }
                if (gridData.Filters != null && dictInfo.SaveColumnFilters != false)
                {
                    foreach (var filterCol in gridData.Filters)
                    {
                        if (gridSavedSettings.Columns.ContainsKey(filterCol.Field))
                        {
                            gridSavedSettings.Columns[filterCol.Field].FilterOperator = filterCol.Operator;
                            gridSavedSettings.Columns[filterCol.Field].FilterValue    = filterCol.ValueAsString;
                        }
                        else
                        {
                            gridSavedSettings.Columns.Add(filterCol.Field, new GridDefinition.ColumnInfo {
                                FilterOperator = filterCol.Operator,
                                FilterValue    = filterCol.ValueAsString,
                            });
                        }
                    }
                }
                GridLoadSave.SaveModuleSettings((Guid)gridData.GridDef.SettingsModuleGuid, gridSavedSettings);
            }
        }