Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New demo: IWGrid + DataTables (and almost no code)

We've been asked to create a demo showing how to use a IWGrid with DataTables ( So here is the online version:

Souce code in our git hub demo repo (link in the online demo)

Please notice that there is almost no code. All code is basically loading the grid from any data source (in that case we load it from a ClientDataSet, but it could be from any source, of course).

The server hosting this demo itself shows another interesting feature of how IW http.sys applications work: Several IW applications running as independent services using the same port (80). (you can see another demo app running in )

Enjoy  Big Grin
Example of loading from custom content handler:

In OnFormCreate:
void __fastcall TCategoryForm::IWAppFormCreate(TObject *Sender)
        "$(document).ready(function() {"
          "$(\"#CATEGORY\").DataTable({ "
            "ordering: false,"
            "ajax: '/Data3',"

      txtHTML->RawText = true;
      txtHTML->Lines->Text =
        "<table class=\"display\" id=\"CATEGORY\">"
        "<th>Check Desc</th>"
        "<th>Activity Desc</th>"
To reload on an async event:
void __fastcall TCategoryForm::btnAsyncClick(TObject *Sender, TStringList *EventParams)
In server controller:
class TContentData3: public TContentBase

    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);


    __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) {


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

  us->qryTmp->Active = false;

  s+="] }";

  return true;
Thanks Alexandre for the example, the link and short description. It really look nice and I'm quite impressed how it looks and what I can do.

and Thanks MJS for the code example. Coding in delphi, it's really not that difficult to find out what's going on the the example.

I have also been through a lot on the homepage, and been trying to figure out how to make use of it in my application.

However a lot of it is new to me and I have, in vain it appears, been trying to see a link to a MS SQL table. I can see that the table itself can be viewed as a matrix and as such it perfect for the concept, but I fail to see how to combine them

I've downloaded the example and tried to figure out how to use one of my SQL tables in stead. Not successfully unfortunately.

Do anybody know how to and if, would you care to share your knowledge ?

Hi Soren,

>> how to use one of my SQL tables in stead.

If you scroll to the bottom of my example you'll see I'm creating the json string (to be passed to a datatable) using a SQL query so should work very similarly in your case.  The keys are setting the ajax parameter in the new datatable, e.g. "ajax: '/Data3'," then creating a custom content handler in IW responding to requests on /Data3 to serve up the required json data to populate the table.  Sample of Delphi custom content handler.
Hi Mark,

Thanks. I did see the Select at the bottom of your script, but did not realize the connection was within the content handler.

I'll check it out and hopefully find a workable solution for me.


Forum Jump:

Users browsing this thread: 1 Guest(s)