ttamturk Posted May 11, 2018 Posted May 11, 2018 Hi everyone, With new uniGUI, GetCellData event became virtual and i just made a sample how to use it with a MVC like template system. You can learn (and download) about mustache and figure a way how to use it. This is just a basic sample. You must download mustache Delphi library from https://mustache.github.io/ I made a custom DBGrid, and names as TenDBGrid for this sample, enjoy. Best regards. TemplateSample.rar 1 Quote
mehmet07 Posted May 31, 2018 Posted May 31, 2018 Tek bir sutun haricinde komple gridi sekillendirmek mümkün müdür? Quote
ttamturk Posted June 7, 2018 Author Posted June 7, 2018 Hmm, DBGrid in her kolonu ayrı cell olarak yaratıldığı için mümkün değil. Bunu sadece örnek olarak koydum, belki ileride daha kapsamlı bir testeği unigui bize sağlayabilir. Ben kendi projelerimde seninle aynı şekilde bir yapıya ihtiyaç duyduğumdan kendimce bir yöntem geliştirdim. Grid üzerinde tek bir kolon bırakıyorum mesela ID kolonu. GetCellData event i içerisnde oluşturduğum json a bütün dataset sahalarını tanımlıyorum ve bu kolon un template inde kullanıyorum. Kendi kullandığım event kodunu göstereyim. function GetCellData(const ColNo: Integer; var HasAttr: Boolean): TUniCellRecord; var template : TaidCrossTemplate; mustache: TSynMustache; function ParseStrToHtml(AHtml : RawUTF8) : RawUTF8; begin Result := StringReplace(AHtml, '"', '\"', [rfReplaceAll]); Result := StringReplace(StringReplace(Result, #10, ' ', [rfReplaceAll]), #13, ' ', [rfReplaceAll]); end; function RecordToJSON(ADataSet : TDataSet) : RawUTF8; var I : Integer; begin Result := ''; if ADataSet.Active then begin Result := '{ '; for I := 0 to ADataSet.Fields.Count - 1 do begin Result := Result + '"' + ADataSet.FieldDefs[I].Name + '": "' + StringReplace(ADataSet.Fields[I].AsString, '"', '\"', [rfReplaceAll]) + '", ' end; Result := LeftStr(Result, Length(Result) - 2) + ' '; Result := Result + ' }'; end; end; begin Result := inherited GetCellData(ColNo, HasAttr); if FContextNo = 0 then begin FContextNo := DataSet.RecNo; FContext := RecordToJSON(DataSet); end; if FContextNo <> DataSet.RecNo then begin FContext := RecordToJSON(DataSet); end; template := TemplateByName(Columns[ColNo].FieldName); if template <> nil then begin mustache := TSynMustache.Parse(ParseStrToHtml(template.HTML.Text)); Result.Value := '"' + mustache.RenderJSON(FContext) + '"'; end; if FContextNo = DataSet.RecordCount then FContextNo := 0; end; Burada RecordToJSON ile oluşan yapı ile template içerisinde bütün dataset i Field isimleri ile kullanabilirsin. <b>{{Id}}</b><br /><span>{{TextFieldName}}, {{TimeFieldName}}</span> gibi. Umarım yardımcı olur. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.