55143681 Posted January 30, 2023 Share Posted January 30, 2023 I use uniDBGrid to input data, after I input field1 and field2 , I want to input field3=field1+field2 automaticly how to do that? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2023 Share Posted January 30, 2023 Hello, You can use calculated fields. Quote Link to comment Share on other sites More sharing options...
55143681 Posted January 30, 2023 Author Share Posted January 30, 2023 13 minutes ago, Sherzod said: Hello, You can use calculated fields. how to use that and how to trigger the action? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2023 Share Posted January 30, 2023 Try to search the forum, google it. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted January 30, 2023 Share Posted January 30, 2023 19 minutes ago, 55143681 said: how to use that and how to trigger the action? Hello, I use this in my server. 1. set uniDBGrid.Column [YourColumn].ShowSummary := True; 2. set this uniDBGrid.JSInterface.JSCode to hide Summary uniDBGrid.JSInterface.JSCode('var me='#1'; var _view=null; var _lockedview=null; if (!me.lockedGrid && !me.normalGrid) {_view=me.getView()} else {_view=me.normalGrid.getView(); _lockedview=me.lockedGrid.getView()}; ' + 'if (_view) {_view.summaryFeature.summaryBar.hide()};' + 'if (_lockedview) {_lockedview.summaryFeature.summaryBar.hide()};' ); 3. set this uniDBGrid.JSInterface.JSCode to show Summary uniDBGrid.JSInterface.JSCode('var me='#1'; var _view=null; var _lockedview=null; if (!me.lockedGrid && !me.normalGrid) {_view=me.getView()} else {_view=me.normalGrid.getView(); _lockedview=me.lockedGrid.getView()}; ' + 'if (_view) {_view.summaryFeature.summaryBar.show()};' + 'if (_lockedview) {_lockedview.summaryFeature.summaryBar.show()};' ); I set this JSCode when create Form for uniDBGrid's uniDBGrid.OnColumnSummaryResult := MyUniDBGridSettingsColumnSummaryResult; procedure MyUniDBGridSettingsColumnSummaryResult( Column: TUniDBGridColumn; GroupFieldValue: Variant; Attribs: TUniCellAttribs; var Result: string); var F : Extended;//Real; StrListSumi : TStringLIst; begin StrListSumi := TStringLIst.Create; try Attribs.Color := $00E2E2E2; Attribs.Font.Size := 8; Attribs.Font.Style := [fsItalic]; if (Column.Field IS TNumericField) AND (Column.Visible) then begin StrListSumi.Add (Column.Title.Caption + '=0'); uniMainModule.fCALCULATESUMCOLUMN (TUniDBGrid (Column.Grid),StrListSumi,False); Result := 'SUM</br>(' + StrListSumi.Values [Column.Title.Caption] + ')';//Format ('%4.2f',[F]);//FormatCurr('0,0.00 ', F);// + FmtSettings.CurrencyString; end; except end; StrListSumi.Clear; StrListSumi.Free; end; function TUniMainModule.fCALCULATESUMCOLUMN (SelDbGrid : TuniDBGrid; SelFields : TStringLIst; ShowTotals : Boolean) :TStringLIst; var k,I,J : Integer; Tryfloat : Extended; sSum : String; MyHeader : TStringGrid; Data : array of Double; MyDBGrid : TDBGrid; B : TBookmark; begin If (not TuniDBGrid (SelDbGrid).DataSource.DataSet.Active) then exit; TRY B := TuniDBGrid (SelDbGrid).DataSource.DataSet.GetBookmark; TuniDBGrid (SelDbGrid).DataSource.DataSet.DisableControls; for I := 0 to TuniDBGrid (SelDbGrid).Columns.Count - 1 do begin if TuniDBGrid (SelDbGrid) = nil then break; if SelFields <> nil then begin if (SelFields.IndexOfName (AnsiUpperCase (TuniDBGrid (SelDbGrid).Columns[I].Title.Caption)) <> -1) then begin sSum := '0.00'; TuniDBGrid (SelDbGrid).DataSource.DataSet.First; if TuniDBGrid (SelDbGrid).DataSource.DataSet.RecordCount > 0 then begin while not TAdoQuery (TuniDBGrid (SelDbGrid).DataSource.DataSet).EOF do begin Try if TuniDBGrid (SelDbGrid).Columns [I].Field <> nil then begin sSum := Calculate (sSum + '+' + TuniDBGrid (SelDbGrid).Columns [I].Field.AsString,6); end; EXCEPT //break; End; TAdoQuery (TuniDBGrid (SelDbGrid).DataSource.DataSet).Next; end; end; SelFields.ValueFromIndex [SelFields.IndexOfName (AnsiUpperCase (TuniDBGrid (SelDbGrid).Columns[I].Title.Caption))] := Calculate (sSum,2); end; end; end; TuniDBGrid (SelDbGrid).DataSource.DataSet.EnableControls; EXCEPT END; Result := SelFields; end; Quote Link to comment Share on other sites More sharing options...
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.