Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by pixie on Apr 28, 2008 06:23
open dhtmlx forum
Please, sorting problem, whatīs wrong!!! ????? :o(

I have this code, the grid loads ok from a table, but when the user click the headers to sort the grid, doesnīt sort correctly. I have modifiy the setColSorting property but donīt fix the problem.
Thnks for any help.



<body>

<script src="dhtmlxgrid_start.js"></script>
<script src="dhtmlxcommon.js"></script>
<script src="dhtmlxgrid.js"></script>
<script src="dhtmlxgridcell.js"></script>
<script src="dhtmlxgrid_start.js"></script>



<table id= 'tblToGrid' class="dhtmlXGrid" imgpath="../../codebase/imgs/" style="width:400px" style="height=600px" lightnavigation="true">
<tr>
    <th align="RIGHT" width=26px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Suc</th>
    <th align="LEFT" width=65px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >....</th>
    <th align="RIGHT" width=103px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Venta Bruta</th>
    <th align="RIGHT" width=103px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Descuentos</th>
    <th align="RIGHT" width=103px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Seņa</th>
    <th align="RIGHT" width=103px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Vales</th>
    <th align="RIGHT" width=103px style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Total </th>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0001" value="1"/><span id="span__CAJSUCNRO_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0001" value="Client S"/><span id="span__SUCNOM_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client S</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0001" value="320640,00"/><span id="span__CAJIMPVTAB_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 320.640,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0001" value="25564,00"/><span id="span__CAJIMPDTO_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 25.564,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0001" value="-100,00"/><span id="span__CAJIMPSENI_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -103,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0001" value="-304,00"/><span id="span__CAJIMPVALE_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -304,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0001" value="294672,00"/><span id="span__TOTSUCDIA_0001" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 294.672,00</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0002" value="2"/><span id="span__CAJSUCNRO_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 2</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0002" value="Client E"/><span id="span__SUCNOM_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client E</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0002" value="338684,00"/><span id="span__CAJIMPVTAB_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 338.684,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0002" value="37771,80"/><span id="span__CAJIMPDTO_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 37.771,80</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0002" value="0,00"/><span id="span__CAJIMPSENI_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 0,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0002" value="-733,80"/><span id="span__CAJIMPVALE_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -733,80</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0002" value="300178,40"/><span id="span__TOTSUCDIA_0002" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 300.178,40</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0003" value="3"/><span id="span__CAJSUCNRO_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 3</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0003" value="Client F"/><span id="span__SUCNOM_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client F</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0003" value="1318851,90"/><span id="span__CAJIMPVTAB_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1.318.851,90</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0003" value="156478,60"/><span id="span__CAJIMPDTO_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 156.478,60</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0003" value="250,00"/><span id="span__CAJIMPSENI_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 250,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0003" value="2151,30"/><span id="span__CAJIMPVALE_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 2.151,30</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0003" value="1164774,60"/><span id="span__TOTSUCDIA_0003" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1.164.774,60</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0004" value="6"/><span id="span__CAJSUCNRO_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 6</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0004" value="Client G"/><span id="span__SUCNOM_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client G</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0004" value="590330,40"/><span id="span__CAJIMPVTAB_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 590.330,40</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0004" value="63038,10"/><span id="span__CAJIMPDTO_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 63.038,10</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0004" value="-50,00"/><span id="span__CAJIMPSENI_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -50,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0004" value="-1664,50"/><span id="span__CAJIMPVALE_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -1.664,50</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0004" value="525577,80"/><span id="span__TOTSUCDIA_0004" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 525.577,80</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0005" value="7"/><span id="span__CAJSUCNRO_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 7</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0005" value="Client D"/><span id="span__SUCNOM_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client D</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0005" value="530911,80"/><span id="span__CAJIMPVTAB_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 530.911,80</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0005" value="58277,10"/><span id="span__CAJIMPDTO_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 58.277,10</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0005" value="0,00"/><span id="span__CAJIMPSENI_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 0,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0005" value="-27,90"/><span id="span__CAJIMPVALE_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -27,90</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0005" value="472606,80"/><span id="span__TOTSUCDIA_0005" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 472.606,80</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0006" value="8"/><span id="span__CAJSUCNRO_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 8</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0006" value="Client C"/><span id="span__SUCNOM_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client C</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0006" value="1087387,70"/><span id="span__CAJIMPVTAB_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1.087.387,70</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0006" value="136431,20"/><span id="span__CAJIMPDTO_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 136.431,20</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0006" value="160,00"/><span id="span__CAJIMPSENI_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 160,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0006" value="-808,40"/><span id="span__CAJIMPVALE_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -808,40</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0006" value="950308,10"/><span id="span__TOTSUCDIA_0006" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 950.308,10</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0007" value="9"/><span id="span__CAJSUCNRO_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 9</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0007" value="Client B"/><span id="span__SUCNOM_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client B</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0007" value="2018940,70"/><span id="span__CAJIMPVTAB_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 2.018.940,70</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0007" value="222183,60"/><span id="span__CAJIMPDTO_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 222.183,60</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0007" value="-100,00"/><span id="span__CAJIMPSENI_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -1102,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0007" value="1058,30"/><span id="span__CAJIMPVALE_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1.058,30</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0007" value="1797715,40"/><span id="span__TOTSUCDIA_0007" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 1.797.715,40</span></td>
</tr>
<tr style="background:transparent;" >
<td valign=top align="RIGHT"><input type="hidden" name="_CAJSUCNRO_0008" value="12"/><span id="span__CAJSUCNRO_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >12</span></td>
<td valign=top align="LEFT"><input type="hidden" name="_SUCNOM_0008" value="Client A"/><span id="span__SUCNOM_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" >Client A</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVTAB_0008" value="655605,00"/><span id="span__CAJIMPVTAB_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 655.605,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPDTO_0008" value="68863,10"/><span id="span__CAJIMPDTO_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 68.863,10</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPSENI_0008" value="-100,00"/><span id="span__CAJIMPSENI_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -101,00</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_CAJIMPVALE_0008" value="-1270,70"/><span id="span__CAJIMPVALE_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > -1.270,70</span></td>
<td valign=top align="RIGHT"><input type="hidden" name="_TOTSUCDIA_0008" value="585371,20"/><span id="span__TOTSUCDIA_0008" style="background:transparent;font-family:'Verdana'; font-size:8pt; font-weight:normal; font-style:normal" > 585.371,20</span></td>
</tr>
</table>

<Script>
    var mygrilla = new dhtmlXGridFromTable('tblToGrid');
mygrilla.setEditable(false);
mygrilla.setColTypes("ro,ro,price,price,price,price,price");
mygrilla.setColSorting("str,str,str,str,str,str,str");
mygrilla.enableColumnAutoSize(true);
mygrilla.setSizes();
</script>

</body>

</html>





Answer posted by Support on Apr 28, 2008 07:24
Actually sorting works correctly , but it threats values as strings , and event if you change your code to
    mygrilla.setColSorting("int,str,int,int,int,int,int");
the sorting will be still incorrect because you are using numbers with additional formatting, which can't be correctly parsed by native parseInt functionality
Answer posted by pixie on Apr 28, 2008 08:08
yes, if i put 585371,20 instead 585.371,20  ( without thousand separator) the sort works correctly.
And how i can format the column to have thousand separator ?  i have tried with  mygrilla.setColTypes("ro,ro,price,price,price,price,price"); but don´t work :o(
hey, sorry for my english, i hope you understand something  :o)
thanks a lot
Answer posted by Support on Apr 29, 2008 04:05
You can have data in original HTML table as plain numbers and add comma separator as part of grid number formating functionality - please check attached sample
Attachments (1)
sample.zip1.10 Kb