Load xml string on grid

hello , am new to dhtmlx , am trying to load data from xml string to my grid , am using layout 3W, and am trying to load a xml string into the grid here is my code

        myLayout.cells("c").setText("Farmer Assets");
      grid2 = myLayout.cells("c").attachGrid();
      grid2.setHeader("id,Farmerid,Asset Number,Asset Type,Animal Type,Breed,Age,weight,Current 
      use,Calvings,Milk yield,body Alignment");
     // grid2.setColumnIds("id,farmerId,assetNumber,assetType,animal_type,breed, age, 
      weight,current_use,calvings,milk_yield,body_alignment");// the columns' ids
      grid2.setInitWidths("20,70,*");//sets the initial widths of columns
      grid2.setColAlign("left,left,left");     //sets the alignment of columns
      grid2.setColTypes("ro,ro,ro");               //sets the types of columns
      grid2.setColSorting("str,str,str");  //sets the sorting types of columns
      grid2.init();
      grid2.parse("<List>
<item>
    <id>1</id>
    <farmerId>1</farmerId>
    <assetNumber>1</assetNumber>
    <assetType>demoData</assetType>
    <animal_type>demoData</animal_type>
    <breed>demoData</breed>
    <age>demoData</age>
    <weight>demoData</weight>
    <current_use>demoData</current_use>
    <calvings>demoData</calvings>
    <milk_yield>demoData</milk_yield>
    <body_alignment>demoData</body_alignment>
</item>
<item>
    <id>2</id>
    <farmerId>2</farmerId>
    <assetNumber>1555057713807</assetNumber>
    <assetType>Livestock</assetType>
    <animal_type>Cow</animal_type>
    <breed>Shshshs</breed>
    <age>Shshaha</age>
    <weight>Sgahahw</weight>
    <current_use>Whshhsha</current_use>
    <calvings>Shsjsjs</calvings>
    <milk_yield>Uwhahwh</milk_yield>
    <body_alignment>Jwhabwhjw</body_alignment>
</item>

,“xml”);

Please, note that you need to use the format of the xml that is supported by the dhtmlxGrid.
Here you can find the template:
https://docs.dhtmlx.com/grid__data_formats.html#xmlformat

Hi sematik, thank you very much for responding , i just wanted to understand , if am trying to load the xmla format from a an api call how would i do that

If you need to load the data in the “xmlA” format, so you need at first to bring the data to the specified xmlA format:

<rows>
    <row id="some1" first="11" second="12" third="13" />
    <row id="some2" first="21" second="22" third="23" />
    <row id="some3" first="31" second="32" third="33" />
</rows>

define the IDs to your columns to assign these columns to the data fields:

grid.setColumnIds("first,second,third");

and define the data format in the load/parse function:

grid.load(url,"xmlA");
//or
grid.parse(data,"xmlA");
1 Like

Thank you , is this the right format for xmla


1
1
1
demoData
<animal_type>demoData</animal_type>
demoData
demoData
demoData
<current_use>demoData</current_use>
demoData
<milk_yield>demoData</milk_yield>
<body_alignment>demoData</body_alignment>


2
2
1555057713807
Livestock
<animal_type>Cow</animal_type>
Shshshs
Shshaha
Sgahahw
<current_use>Whshhsha</current_use>
Shsjsjs
<milk_yield>Uwhahwh</milk_yield>
<body_alignment>Jwhabwhjw</body_alignment>

i want to pass it to an object then load the grid

Could you please, please, provide an original non-formatted xml,

<List>
    <item>
        <id>1</id>
        <farmerId>1</farmerId>
        <assetNumber>1</assetNumber>
        <assetType>demoData</assetType>
        <animal_type>demoData</animal_type>
        <breed>demoData</breed>
        <age>demoData</age>
        <weight>demoData</weight>
        <current_use>demoData</current_use>
        <calvings>demoData</calvings>
        <milk_yield>demoData</milk_yield>
        <body_alignment>demoData</body_alignment>
    </item>
    <item>
        <id>2</id>
        <farmerId>2</farmerId>
        <assetNumber>1555057713807</assetNumber>
        <assetType>Livestock</assetType>
        <animal_type>Cow</animal_type>
        <breed>Shshshs</breed>
        <age>Shshaha</age>
        <weight>Sgahahw</weight>
        <current_use>Whshhsha</current_use>
        <calvings>Shsjsjs</calvings>
        <milk_yield>Uwhahwh</milk_yield>
        <body_alignment>Jwhabwhjw</body_alignment>
    </item>
</List>

You need to create your own custom data loading type.
Here you can find a tutorial:
https://docs.dhtmlx.com/grid__data_formats.html#customdataformat

okay would i be given a sample code that loads data into a grid form an object in xml format

how do you load from an api call into a grid

In case of loading the data from a local object please, try to use the parse() method:
https://docs.dhtmlx.com/api__dhtmlxgrid_parse.html
Here you can find a sample:
https://dhtmlx.com/docs/products/dhtmlxGrid/samples/12_initialization_loading/09_init_grid_json.html

Thank you semantic, That really helped a lot