CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Using Grid as simple String-Grid

General discussion

by wieczy » 12 Jun 2012 12:59

Hi,

I try to use a TIWCGJQGrid as simply "string-grid" to show a small number of values. The following code has no effect:

--8<---

String xmlstring = " \
\
\
1 \
2 \
3 \
4 \
\
\
";

IWCGJQGrid2->JQGridOptions->DataType = gdtXmlString;
IWCGJQGrid2->JQGridOptions->DataStr = xmlstring;

---8<---

ColModel is initializided with 4 columns. Is there anything else to do?

Greetings

Frank.
wieczy
 
Posts: 4
Joined: 07 Jun 2012 07:29

by wieczy » 12 Jun 2012 13:05

...uupps the forum software has the xmlstring destroyed...

Hmmm... I do not know, how to post xml-strings... sorry
wieczy
 
Posts: 4
Joined: 07 Jun 2012 07:29

by Pedro » 12 Jun 2012 17:55

Hi Wieczy

The method you're using is correct.

But the XML its important to know what's wrong, and depends on XMLReader properties.

Could you please send us your XML by email.

By the way a new version was published minutes ago, with some important additions, like the grid events for select that we've discuss before, and some bug fixes.

Best Regards
Pedro
 
Posts: 14
Joined: 24 May 2012 19:38

by wieczy » 18 Jun 2012 12:29

Hi,

with a correct xml-string it works very well.

Thank you fpr support.

Bets regards

Frank.
wieczy
 
Posts: 4
Joined: 07 Jun 2012 07:29

by ScottWGast » 18 Jul 2012 18:19

I have an existing TIWGrid that I am using as a string grid (along with adding a few button and link objects in the cells), but I am using CSV data. Currently, I iterate through the CSV data and populate the TIWGrid with string values, buttons, links, etc. Do you have an example of this using the TIWCGJQGrid?

Thanks,
Scott Gast
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by Jorge Sousa » 18 Jul 2012 18:35

Hi Scott

While I'm preparing a simple demo, here's a briefing:

According to plugin's documentation in:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data

you can use direct xml data or direct json data

to set xml direct data

set your IWGrid.JQGridOptions.DataType:= gdtXmlString;
Add the columns you need to the grid

and do something like this to set XML Data, for instance in IWForm.OnCreate:

var
XMLDoc: IXMLDocument;
RowsNode: IXMLNode;
RowNode: IXMLNode;
Row,Field: Integer;
CellNode: IXMLNode;
begin
XMLDoc:= NewXMLDocument();
try
RowsNode:= XMLDoc.AddChild('rows');
// RowsNode.AddChild('page').NodeValue:= 1;

for Row:= 1 to 10 do
begin
RowNode:= RowsNode.AddChild('row');

for Field:= 1 to 3 do
begin
CellNode:= RowNode.AddChild('cell');
CellNode.NodeValue:= 'Row'+IntToStr(Row)+' Field'+IntToStr(Field);
end;
end;

IWGrid..JQGridOptions.DataStr:= XMLDoc.XML.Text;
finally
XMLDoc:= nil;
end;
end;

You can even set a form XMLDoc property if you need edition.

And you can use GridCollectionProvider assigned to a collection, like:

type
TMyCollectionItem = class(TCollectionItem)
private
// members
published
property S: string read fS write fS;
property I: Integer read fI write fI;
end;

TMyCollection = class(TColllection)
public
constructor Create;
end;

constructor TMyCollection.Create;
begin
inherited Create(TMyCollectionItem);
end;

Whatever published properties in TMyCollectionItem will be linked to Grid, if a GridCollectionProvider is used.

Best Regards

Jorge
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by ScottWGast » 19 Jul 2012 15:22

I see that you are using XML in your sample code above, that is fine with me... I can use CSV or XML. The primary reason is that I want to use a dataset that is not connected to the SQL Server. I retrieve the data from SQL server (using ADO) and then convert that data to either CSV or XML.

I have a simple grid with a single column that I want to contain the data field "caseid".
Question: Where in the grid column properties do I set the field name from the XML dataset?

Here is a snippet of my code:
var
xmlGridData: IXMLDocument;
begin
Self.xmlGridData := UserSession.GetCaseListXML; // returns IXMLDocument
Self.gridJQuery.JQGridOptions.DataType := gdtXmlString;
Self.gridJQuery.JQGridOptions.DataStr := Self.xmlGridData.XML.Text;
end;

Thanks,
Scott
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by Jorge Sousa » 19 Jul 2012 16:02

Hi Scott

use Col.Name

Col:= gridJQuery.JQGridOptions.ColModel.Add;
Col.Name:= 'SomeName';

Anyway for XML Direct Data (Self.gridJQuery.JQGridOptions.DataType := gdtXmlString), the Col.Name it's not important, what matters is the column order to be matched with XML RowsNode child nodes order

if the Col will have the key field, set Col.Key:= True.

This is important for Grid Edit and Delete.

you can hide it with Col.Hidden:= True;

Look at our online documentation, or in the .CHM file included in CGComps installation path for the several options. Documentation is still a working progress, there's still a lot to document, mainly for the Grid, which is very complex.

About the XML Data, There are other alternatives as welll, including json data, colllections GridEventProvider where you define by events what to do on OnGet, OnAdd OnEdit, OnDelete (TreeGrid in Demo uses it).

And also
JQGridOptions.AddRow, JQGridOptions.SetCelll

Like I said, We are preparing a demo showing with all those alternatives.

if your XML Data has too many correspondent rows, passing the whole XMLData is not the best solution. Working with providers, the grid requests the server whenever it needs data or any other operation.

Best Regards

Jorge
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by ScottWGast » 19 Jul 2012 16:22

For this particular scenario, the number of rows is very small (less than 25), so I would like to all of the the XMLData rather than using a data provider. Once I get it working, I will move on to figuring out the data providers.

I have created two columns on my grid using the column editor (right-click/columns) and have set the column names to match the XML field names. .Key is True for field "caseid", but when I run the application, the grid shows up with two columns, but no data. I inspect the XML data at run time and it is correct.
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by Jorge Sousa » 19 Jul 2012 16:35

Hi again Scott

Like I posted previously:

"... for XML Direct Data (Self.gridJQuery.JQGridOptions.DataType := gdtXmlString), the Col.Name it's not important, what matters is the column order to be matched with XML RowsNode child nodes order"

your XML should be something like (replace "(" with "less" symbol" and ")" with "greater" symbol - I can't use that chars in forum):

(?xml version="1.0"?)
(rows)
(row)
(cell)Row1 Field1(/cell)
(cell)Row1 Field2(/cell)
(/row)
(row)
(cell)Row2 Field1(/cell)
(cell)Row2 Field2(/cell)
(/row)
(row)
(cell)Row3 Field1(/cell)
(cell)Row3 Field2(/cell)
(/row)
(/rows)
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

Next

Return to General - Archive

Who is online

Users browsing this forum: No registered users and 9 guests

Contact Us.