private static void InitFormConfig <T>(DataTableBuilder <T> dtBuilder, DtModel dtModel) where T : class { if (!dtBuilder.DataTableDataSourceBuilder.IsUsedInForm) { return; } dtModel.IsUsedInForm = true; dtModel.FormId = dtBuilder.DataTableDataSourceBuilder.FormId; if (dtBuilder.DataTableDataSourceBuilder.SubmitWithMultiHiddenInputs) { dtModel.SubmitWithMultiHiddenInputs = true; dtModel.PrefixForMultiHiddenInputs = dtBuilder.DataTableDataSourceBuilder.PrefixForMultiHiddenInputs; } else // A single hiden input that will hold all values as json { dtModel.NameAttributeForHiddenInputHoldingTableData = $"name='{dtBuilder.DataTableDataSourceBuilder.StringPropNameForSubmittedValues}'"; } if (dtBuilder.DataTableDataSourceBuilder.IsSubmitOnlyNewAndModifiedRows) { dtModel.IsSubmitOnlyNewAndModifiedRows = true; } }
internal static DtModel InitInstance <T>(DataTableBuilder <T> dtBuilder) where T : class { var dtModel = new DtModel { TableName = dtBuilder.TableName, TableClassName = $"{(dtBuilder.TableOptionsFactory.HasClassName ? $" {dtBuilder.TableOptionsFactory.ClassName}" : string.Empty)}", IdOfHiddenInputHoldingTableData = $"dt_{dtBuilder.TableName}_data", IsDtAjaxLoadingDefferd = "false", TableDefaultDatesFormat = dtBuilder.TableOptionsFactory.TableDefaultDatesFormat }; if (dtBuilder.TableOptionsFactory.DoCreateApiInstance) { dtModel.DoCreateDtApiInstance = true; dtModel.DtApiInstanceName = dtBuilder.TableOptionsFactory.DtApiInstanceName; } InitDataTableConfig <T>(dtBuilder, dtModel); InitFormConfig(dtBuilder, dtModel); InitNativeDtEventsConfig(dtBuilder, dtModel); InitOnClickEventsConfig(dtBuilder, dtModel); return(dtModel); }
private static void InitDataTableConfig <T>(DataTableBuilder <T> dtBuilder, DtModel dtModel) where T : class { JObject jObject = new JObject(); //Table Options if (dtBuilder.TableOptionsFactory != null) { jObject = (JObject)dtBuilder.TableOptionsFactory.ToJToken(); } // Columns if (dtBuilder.DtaTableColumnsFactory != null) { jObject.Add("columns", dtBuilder.DtaTableColumnsFactory.ToJToken()); var columnsWithOrder = dtBuilder.DtaTableColumnsFactory.Columns.Where(c => !string.IsNullOrEmpty(c.OrderDirection)).ToList(); if (columnsWithOrder != null && columnsWithOrder.Any()) { jObject.Add("order", dtBuilder.DtaTableColumnsFactory.BuildOrdersJToken()); } } //Select if (dtBuilder.DtaTableColumnsFactory.Columns.Any(c => c.IsCheckBoxColumn)) { jObject.Add("select", new JObject { { "style", new JValue("multi") } }); } //Buttons if (dtBuilder.DataTableButtonsFactory != null && dtBuilder.DataTableButtonsFactory.Buttons.Any()) { jObject.Add("buttons", dtBuilder.DataTableButtonsFactory.ToJToken()); } //Ajax if (dtBuilder.DataTableDataSourceBuilder != null && dtBuilder.DataTableDataSourceBuilder.AjaxBuilder != null) { jObject.Add("ajax", new JRaw($@"function (data, callback, settings) {{ if (_isDtAjaxLoadingDefferd) {{ _isDtAjaxLoadingDefferd = false; callback({{data: []}}); // don't fire ajax, just return empty set return; }} $.ajax({ dtBuilder.DataTableDataSourceBuilder.ToJToken()}); }}")); } //Pour intialiser la datasource par les items du Model (note: problème avec le html) if (dtBuilder.DataTableDataSourceBuilder != null && dtBuilder.DataTableDataSourceBuilder.Items != null && dtBuilder.DataTableDataSourceBuilder.Items.Any()) { var items = JsonConvert.SerializeObject(dtBuilder.DataTableDataSourceBuilder.Items, new JsonSerializerSettings { DateFormatString = dtModel.TableDefaultDatesFormat.ToLower() }); jObject.Add("data", new JRaw(items)); } dtModel.CustomConfigValues = jObject.ToString(Newtonsoft.Json.Formatting.None); if (dtBuilder.DataTableDataSourceBuilder != null && dtBuilder.DataTableDataSourceBuilder.AjaxBuilder != null && dtBuilder.DataTableDataSourceBuilder.AjaxBuilder.IsDtAjaxLoadingDefferd) { dtModel.IsDtAjaxLoadingDefferd = "true"; } if (dtBuilder.TableOptionsFactory.HasDefaultSettings) { dtModel.HasDefaultSettings = true; dtModel.DefaultConfigValues = dtBuilder.TableOptionsFactory.DefaultSettings; } }
private static void InitNativeDtEventsConfig <T>(DataTableBuilder <T> dtBuilder, DtModel dtModel) where T : class { if (dtBuilder.DataTableEventsFactory != null) { dtModel.NativeEvents = dtBuilder.DataTableEventsFactory.ToString(); } if (dtBuilder.DtaTableColumnsFactory.Columns.Any(c => c.IsCheckBoxColumn)) { dtModel.HasCheckBoxColumn = true; } if (dtBuilder.DtaTableColumnsFactory.Columns.Any(c => c.IsEditRowCommand)) { DataTableCommandEditBuilder dtCommandEditBuilder = ((DataTableCommandEditBuilder)dtBuilder.DtaTableColumnsFactory.Columns.First(c => c.IsEditRowCommand)); dtModel.HasEditRowCommand = true; dtModel.EditPopupTitle = dtCommandEditBuilder.EditPopupTitle; dtModel.FetchEditViewFromServerSide = dtCommandEditBuilder.IsServerSide; dtModel.FetchEditViewFromUrl = dtCommandEditBuilder.FetchViewFromUrl; dtModel.ValidateEditViewByUrl = dtCommandEditBuilder.ValidateByUrl; } }
private static void InitOnClickEventsConfig <T>(DataTableBuilder <T> dtBuilder, DtModel dtModel) where T : class { if (dtBuilder.DtaTableColumnsFactory.Columns.Any(c => !string.IsNullOrEmpty(c.Click))) { dtModel.HasClickEvents = true; dtModel.ClickEvents = string.Join(",", dtBuilder.DtaTableColumnsFactory.Columns.Select(e => e.Click)); } }