Hi
I have a TIWCGJQDropDown on my form, containing 2500 items, on our production evironment , opening the dropdown is very slow.
I have pre-loaden all items in the create of the form.
Is there any better way (performance wise) to do this?
Eric
IWCGJQDropDownSelect.JQDropDownOptions.AttachTo:= jqddatInput;
IWCGJQDropDownSelect.JQDropDownOptions.MinimumInputLength:= 2;
IWCGJQDropDownSelect.OnGetDropDownData:= IWCGJQDropDownSelectGetDropDownData;
IWCGJQDropDownSelect.JQDropDownOptions.InfiniteScroll:= True;
IWCGJQDropDownSelect.JQDropDownOptions.Ajax.QuietMillis:= 100;
procedure TIWJQDropDownFrame.IWCGJQDropDownSelectGetDropDownData(Sender: TObject; const ATerm: string;
const APage: Integer; var AJSon: ISuperObject; var AIsMore: Boolean);
const
PageRecs = 50;
var
DescField: TField;
ItemJSon: ISuperObject;
SQL: string;
RecPos: Integer;
i: Integer;
begin
SQL:= 'select * from products where ProductDescription like ' + QuotedStr('%'+ATerm+'%');
if not ADOQuery.Active or (SQL <> ADOQuery.SQL.Text) then
begin
ADOQuery.Close;
ADOQuery.SQL.Text:= SQL;
ADOQuery.Open;
end;
DescField:= ADOQuery.FieldByName('ProductDescription');
AJSon:= TSuperObject.Create(stArray);
if APage = 0 then // ALL
begin
ADOQuery.First;
while not ADOQuery.Eof do
begin
ItemJSon:= TSuperObject.Create(DescField.AsString);
AJSon.AsArray.Add(ItemJSon);
ADOQuery.Next;
end;
end
else // FETCH PageRecs
begin
RecPos:= Pred(APage)*PageRecs;
if RecPos < 1 then
RecPos:= 1;
if ADOQuery.RecNo <= 0 then
begin
ADOQuery.First;
if ADOQuery.MoveBy(RecPos-1) <> RecPos-1 then Exit;
end
else
begin
ADOQuery.MoveBy(RecPos - ADOQuery.RecNo);
if ADOQuery.RecNo <> RecPos then Exit;
end;
i:= 0;
while not ADOQuery.Eof and (i < PageRecs) do
begin
ItemJSon:= TSuperObject.Create(DescField.AsString);
AJSon.AsArray.Add(ItemJSon);
ADOQuery.Next;
inc(i);
end;
AIsMore:= not ADOQuery.Eof;
end;
end;
etwoss wrote:Hi
Thanks, this is working fine, it ther any way to still use the ID field (so not only have a description but also an ID) so i can use datalink to the ID.
Eric
JSonObjArr:= TSuperObject.Create(stArray);
JSonObj:= SO();
JSonObj.S['id']:= 'CA';
JSonObj.S['text']:= 'California';
JSonObjArr.AsArray.Add(JSonObj);
JSonObj:= SO();
JSonObj.S['id']:= 'MA';
JSonObj.S['text']:= 'Massachusetts';
JSonObjArr.AsArray.Add(JSonObj);
...
...
while not ADOQuery.Eof do
begin
ItemJSon:= SO();
ItemJSon.S['value']:= ADOQuery.FieldByName('IdFieldName').asString; //here you store the ID
ItemJSon.S['label']:= ADOQuery.FieldByName('DescriptionFieldName').asString; //here you store the Description Value
ItemJSon.S['text']:= ADOQuery.FieldByName('DescriptionFieldName').asString; ///this optional and dont know really what that is for :D but try to assign the same value as you do for 'label'
AJSon.AsArray.Add(ItemJSon);
ADOQuery.Next;
end;
...
...