TWebAccordion rendering items

Hi there,

I want to add itens under the TWebAccprdopm section only when the user expand the section.

However I have to wait for the XDataWebDataSet to retrieve the data.

procedure TFormMain.WACardapioExpanding(Sender: TObject; ASection: TAccordionSection; var Allow: Boolean);
begin
FCurrentPanel := ASection.PanelElement;
XDataWebDataSetItem.Close;
XDataWebDataSetItem.QueryString := '$filter=(grupo/parent/ordem eq '''+ASection.Tag.ToString+''') and (ativo eq true) and (intwebdeliverypublicar eq true) and (dominio eq '+FDominio.Tostring+')';
XDataWebDataSetItem.Load;
end;

The users click on the accordion section and the event above is executed, the PanelElement gets stored

and the XDataWebDataSet is set to load the data

procedure TFormMain.XDataWebDataSetItemAfterOpen(DataSet: TDataSet);
var
lb: TWebListControl;
begin
WACardapio.BeginUpdate;
lb := TWebListControl.Create(Self);
lb.ParentElement := FCurrentPanel;
lb.HeightStyle := ssAuto;
lb.WidthStyle := ssAuto;
lb.Style := lsListGroup;

XDataWebDataSetItem.First;
while not XDataWebDataSetItem.Eof do
begin
lb.Items.Add.Text := XDataWebDataSetItem.FieldByName('nome').AsString;
XDataWebDataSetItem.Next;
end;
WACardapio.EndUpdate;
end;

When the data arrives, it tries to use that PanelElement from the expanded section to put a List Control qwith the data inside.

The is retrieved ok, however no Items are displayed. Sections are showing all fine, and the current section is just opened no items

Whats wrong?

====================

another question based on this one, instead using
lb.Items.Add.Text := XDataWebDataSetItem.FieldByName('nome').AsString;

I dont want just a Text, I want a HTML with text, descritption, Image etc,.... can I just put o this TEXT in HTML and will be fine?

Thank you

I have changed a lot the code and see that to take effect a change on accordion I need to use Accordion.BeginUpdate and Accordion.EndUpdate

Doing that, the accordion is refreshed and the rendering of the sections begin rendering again....

Seems that I have only one chance to update de accordion

What is need is to fill in the section when the user expand them and keep the data there. Otherwise I will have a lot of retrieval from the server.

probably i was not clear enough .....

I would like to know how to fill in an TWebAccordion on the fly... only when the section is expanded...

When expanding event is fired I need to bring data throu XDataWebDataSet.Load

When XDataWebDataSet.AfterOpen is fired (data arrived) I want to fill the accordion section that is expanded...

All attempts does not show any information on the page...

Any help how to do that?

This sample code will asynchronously fill the content of a section with data retrieved from a HTTP request:

unit Unit1;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, WEBLib.ExtCtrls, WEBLib.REST;

type
  TForm1 = class(TWebForm)
    WebAccordion1: TWebAccordion;
    WebHttpRequest1: TWebHttpRequest;
    procedure WebAccordion1Expanding(Sender: TObject;
      ASection: TAccordionSection; var Allow: Boolean);
    procedure WebHttpRequest1Response(Sender: TObject; AResponse: string);
  private
    { Private declarations }
  public
    { Public declarations }
    ActiveSection: TAccordionSection;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  WEBLib.JSON;

procedure TForm1.WebAccordion1Expanding(Sender: TObject;
  ASection: TAccordionSection; var Allow: Boolean);
begin
  ActiveSection := ASection;
  WebHttpRequest1.URL := 'https://jsonplaceholder.typicode.com/todos/'+inttostr(ASection.Index+1);
  WebHttpRequest1.Execute;
end;

procedure TForm1.WebHttpRequest1Response(Sender: TObject; AResponse: string);
var
  js:TJSON;
  jo: TJSONObject;
  jv: TJSONValue;
begin
  js := TJSON.Create;
  jo := js.Parse(AResponse);

  jv := jo.GetValue('title');
  ActiveSection.PanelElement.innerHTML := jv.Value;
end;