EasyUI Forum
October 10, 2024, 09:54:32 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid Multiple Sorting - sorting wrongly bug?  (Read 9104 times)
rannacher
Jr. Member
**
Posts: 52


View Profile
« on: December 05, 2018, 02:15:46 PM »

Hello,

I wonder if anybody ever noted, that the multiple sorting on the demo page is actually sorting wrong?

1. looking here https://www.jeasyui.com/easyui/demo/datagrid/multisorting.html
2. click "Unit Cost" sort as first column (where the many 12 are)
3. click "List Price" sort as second column
 
With this all "Unit Cost" rows are sorted correctly, but within the "Unit Cost=12" group
a lot of rows get sorted correctly, but then ItemID EST-14 with List Price 158 gets listed below 18.5
which is so far the lowest List Price. ASC/DESC of List price same problem.

Hope I dont get anything wrong here.
Help very much appreciated.

Thx a lot,
Mike.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2274


View Profile Email
« Reply #1 on: December 05, 2018, 05:14:36 PM »

The 'listprice' and 'unitcost' values bound on the datagrid are string values. They should be converted to number values before sorting. This issue has been fixed, please try it again.
https://www.jeasyui.com/easyui/demo/datagrid/multisorting.html
Logged
rannacher
Jr. Member
**
Posts: 52


View Profile
« Reply #2 on: December 05, 2018, 05:21:26 PM »

Thanks a lot Jarry, I was assuming this but could/cannot solve it in my code.

I also introduced a sorter function in the table with just these 2 columns,
but the sort function is always showing the values of the first column for comparison.

Any idea???

QUOTE/CODE
<table id="dg" class="easyui-datagrid" title="Multiple Sorting" style="width:1000px;height:400px"
        data-options="
            singleSelect:true,
            collapsible:true,
            remoteSort:false,
            multiSort:true
        ">
    <thead>
        <tr>
            <th data-options="field:'productname',width:100,sortable:true,sorter:MMRDatagridSorter">ProductName</th>
            <th data-options="field:'listprice',width:80,align:'right',sortable:true,sorter:MMRDatagridSorter">List Price</th>
        </tr>
    </thead>
</table>
<div id="mrrconsole"></div>

<script type="text/javascript" src="includes/JS/mrr-main.js"></script>

<script>



//var gDEBUG_LEVEL = 0;  

function MMRDatagridSorter(a,b)
{
  var a_pure = strip(a);
  var b_pure = strip(b);
  logconsole("MMRDatagridSorter(): a_pure=["+a_pure+"] b_pure=["+b_pure+"]");
  
  if ( (a_pure.length == 10) && (a_pure.substr(2,1) == '.') && (a_pure.substr(5,1) == '.') &&
       (b_pure.length == 10) && (b_pure.substr(2,1) == '.') && (b_pure.substr(5,1) == '.')  
     )
  {
    logconsole(' => date');
    a = a_pure.split('.');
    b = b_pure.split('.');
    logconsole(' => date a=['+a+'] b=['+b+']');
    if (a[2] == b[2])
    {
        logconsole(" => (a[2] == b[2]) TRUE" );
        if (a[1] == b[1])
        {
            logconsole(" => (a[1] == b[1]) TRUE return=" + (a[0]>b[0]?1:-1) );
            return (a[0]>b[0]?1:-1);
        } else
        {
            logconsole(" => (a[1] == b[1]) FALSE return=" + (a[1]>b[1]?1:-1) );
            return (a[1]>b[1]?1:-1);
        }
    } else
    {
        logconsole(" => (a[2] == b[2]) FALSE return=" + (a[2]>b[2]?1:-1) );
        return (a[2]>b[2]?1:-1);
    }
  }
  else if ( !isNaN(a_pure) && !isNaN(b_pure) )
  {
    logconsole(' => both numbers return=' + ( (parseFloat(a_pure)>parseFloat(b_pure))? 1: -1) );
    return ( (parseFloat(a_pure)>parseFloat(b_pure))? 1: -1);
  }
  else
  {
    logconsole(' => neither date nor numbers return=' + (a_pure>b_pure?1:-1) );
    return (a_pure>b_pure?1:-1);
  }
}
UNQUOTE/CODE
Logged
rannacher
Jr. Member
**
Posts: 52


View Profile
« Reply #3 on: December 06, 2018, 10:02:17 AM »

GOT IT!
Thanks Jarry!!!
Logged
jarry
Administrator
Hero Member
*****
Posts: 2274


View Profile Email
« Reply #4 on: January 12, 2019, 06:11:07 PM »

You can define the 'sorter' function for the column to custom the sorting logic. Here is the example to sort a Date column.
Code:
$('#dg').datagrid({
remoteSort: false,
columns: [[
{field:'date',title:'Date',width:80,sortable:true,align:'center', 
sorter:function(a,b){ 
a = a.split('/'); 
b = b.split('/'); 
if (a[2] == b[2]){ 
if (a[0] == b[0]){ 
return (a[1]>b[1]?1:-1); 
} else { 
return (a[0]>b[0]?1:-1); 

} else { 
return (a[2]>b[2]?1:-1); 


}
]]
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!