jemmyhatta Posted January 26, 2015 Share Posted January 26, 2015 How to make DBGRID can scroll up or down automatically to approach the searched data as the usual dbgrid in desktop version? I mean when the data is being searched using findkey / locate / findnearest, the "pointer" on dbgrid can really focus on the searched data record and the scrollbar can up an down automatically following the result. Best Regards. Link to comment Share on other sites More sharing options...
Sherzod Posted January 27, 2015 Share Posted January 27, 2015 Hi, While, maybe it will help: for example: ... procedure TMainForm.UniButton1Click(Sender: TObject); var gridJSName: string; begin gridJSName := UniDBGrid1.JSName; if ClientDataSet1.Locate('EmpNo', UniEdit3.Text, [loPartialKey, loCaseInsensitive]) then begin if UniDBGrid1.WebOptions.Paged then UniSession.AddJS(gridJSName + '.getView().select('+ gridJSName +'.store.findRecord(''0'',' +UniEdit3.Text+')); '+ gridJSName +'.getView().focusRow('+IntToStr((ClientDataSet1.RecNo-1)mod UniDBGrid1.WebOptions.PageSize)+');') else UniSession.AddJS(gridJSName + '.getView().select('+ gridJSName +'.store.findRecord(''0'',' +UniEdit3.Text+')); '+ gridJSName +'.getView().focusRow('+IntToStr(ClientDataSet1.RecNo-1)+');'); end; end; ... Best regards. Link to comment Share on other sites More sharing options...
jemmyhatta Posted January 27, 2015 Author Share Posted January 27, 2015 Hi, I've already tried your method, and the result is not perfect yet (some is working, but some is not (yet)). 1. Using "ClientDataset" with biolife.cds database --> Success 2. Using "ADOTABLE" with MS.ACCESS database --> Success 3. Using either "ADOTABLE" nor "FIREDAC" with MSSQLSERVER database --> not working and there're errors like these : _rsov_(O5A,0);O62.getView().select(O62.store.findRecord('0',U001)); O62.getView().focusRow(13);O66.loadPage(2,{params:{start:25,limit:25,options:1}}); I've attached the source code: For Table on MSSQLSERVER just made them with the script below : CREATE TABLE [dbo].[MHCustomer]( [Kode] [varchar](10) NOT NULL, [Nama] [varchar](100) NULL, [Kelompok] [varchar](2) NULL, [KodeCOA] [varchar](50) NULL, [userId] [varchar](25) NULL, [TglInput] [datetime] NULL, CONSTRAINT [PK_MHCustomer] PRIMARY KEY CLUSTERED( [Kode] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GO Best Regards, Project4.zip Link to comment Share on other sites More sharing options...
Sherzod Posted January 27, 2015 Share Posted January 27, 2015 Error: store.findRecord('0',U001) Info: store.findRecord("fieldIndex", "searchValue"); Corrected: ... procedure TMainForm.UniButton1Click(Sender: TObject); var gridJSName: string; begin gridJSName := UniDBGrid1.JSName; if ClientDataSet1.Locate('EmpNo', UniEdit3.Text, [loPartialKey, loCaseInsensitive]) then begin if UniDBGrid1.WebOptions.Paged then UniSession.AddJS(gridJSName + '.getView().select('+ gridJSName +'.store.findRecord("0","' +UniEdit3.Text+'")); '+ gridJSName +'.getView().focusRow('+IntToStr((ClientDataSet1.RecNo-1)mod UniDBGrid1.WebOptions.PageSize)+');') else UniSession.AddJS(gridJSName + '.getView().select('+ gridJSName +'.store.findRecord("0","' +UniEdit3.Text+'")); '+ gridJSName +'.getView().focusRow('+IntToStr(ClientDataSet1.RecNo-1)+');'); end; end; ... 1 Link to comment Share on other sites More sharing options...
jemmyhatta Posted January 28, 2015 Author Share Posted January 28, 2015 Thanks....It works Link to comment Share on other sites More sharing options...
Recommended Posts