Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New demo: IWGrid + DataTables (and almost no code)
#2
Code:
Example of loading dataTables.net from custom content handler:

//---------------------------------------------------------------------------
In OnFormCreate:
//---------------------------------------------------------------------------
void __fastcall TCategoryForm::IWAppFormCreate(TObject *Sender)
{
      ExtraHeader->Add(
      "<script>"
        "$(document).ready(function() {"
          "$(\"#CATEGORY\").DataTable({ "
            "ordering: false,"
            "ajax: '/Data3',"
          "});"
        "});"
      "</script>"
      );

      txtHTML->RawText = true;
      txtHTML->Lines->Text =
        "<table class=\"display\" id=\"CATEGORY\">"
        "<thead>"
        "<tr>"
        "<th>ID</th>"
        "<th>Name</th>"
        "<th>Type</th>"
        "<th>Check Desc</th>"
        "<th>Activity Desc</th>"
        "</tr>"
        "</thead>"
        "</table>"
        ;
}
//---------------------------------------------------------------------------
To reload on an async event:
//---------------------------------------------------------------------------
void __fastcall TCategoryForm::btnAsyncClick(TObject *Sender, TStringList *EventParams)
{
  WebApplication->CallBackResponse->AddJavaScriptToExecuteAsCDATA(
  "$(\"#CATEGORY\").DataTable().ajax.reload(null,false);"
  );
}
//---------------------------------------------------------------------------
In server controller:
//---------------------------------------------------------------------------
class TContentData3: public TContentBase
{
  protected:

    virtual bool __fastcall Execute(Iw::Http::Request::THttpRequest* aRequest, Iw::Http::Reply::THttpReply* aReply, const System::UnicodeString aPathname, Iwapplication::TIWApplication* aSession, System::Classes::TStrings* aParams);

  public:

    __fastcall TContentData3(void);

};
//---------------------------------------------------------------------------
void __fastcall TIWServerController::IWServerControllerBaseConfig(TObject *Sender)
{
    THandlers::Add("","/Data3", new TContentData3());
}
//---------------------------------------------------------------------------
__fastcall TContentData3::TContentData3(void)
{
  mFileMustExist = false;
  mRequiresSessionStart = true;
}
//---------------------------------------------------------------------------
bool __fastcall TContentData3::Execute(Iw::Http::Request::THttpRequest* aRequest, Iw::Http::Reply::THttpReply* aReply, const System::UnicodeString aPathname, Iwapplication::TIWApplication* aSession, System::Classes::TStrings* aParams)
{
  TIWUserSession *us = (TIWUserSession*)WebApplication->Data;
  us->qryTmp->Active = false;
  us->qryTmp->SQL->Text = "SELECT * FROM CATEGORY ORDER BY ID;";
  us->qryTmp->Active = true;

  aReply->ContentType = "text/plain";
  String s = "{ \"data\": [";
  while(!us->qryTmp->Eof) {

    s+="["
        "\""+us->qryTmp->FieldByName("ID")->AsString+"\","
        "\""+us->qryTmp->FieldByName("NAME")->AsString+"\","
        "\""+us->qryTmp->FieldByName("TYPE")->AsString+"\","
        "\""+us->qryTmp->FieldByName("DATA_COL1")->AsString+"\","
        "\""+us->qryTmp->FieldByName("DATA_COL2")->AsString+"\""
        "]";

    if(us->qryTmp->RecNo < us->qryTmp->RecordCount) { s+=","; }

    us->qryTmp->Next();
  }
  us->qryTmp->Active = false;

  s+="] }";

  aReply->WriteString(s);
  return true;
}
//---------------------------------------------------------------------------
Reply


Messages In This Thread
Example loading dataTables.net from custom content handler - by MJS@mjs.us - 02-20-2020, 08:06 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)