Ignore empty cells when sorting by groups

Ignore empty cells when sorting by groups

imacimac Posts: 19Questions: 0Answers: 0
edited February 2013 in General
I have a table with two groups of colums. Half left and half right. The rows at the left are related to the ones at the right so that one row in the left can be related to many rows at the right.

I won't use any sorting options for the half right side of the table but I would like to add this options for the ones in the left side.

The thing is that the number of rows in the left side still being the same as the rows in the right but some of them are empty. () in order to show the relation between the rows at the left side and the ones at the right side.

Here an image of what I'm talking about:
http://i.stack.imgur.com/ZNLOG.gif

I have managed to order it by group: (by the second column)
[code]
var table = $('.tlmTable').dataTable(options).rowGrouping({
iGroupingColumnIndex: 1,
sGroupingColumnSortDirection: "asc",
iGroupingOrderByColumnIndex: 1,
bHideGroupingColumn:false,
bHideGroupingOrderByColumn:false,
});
[/code]

But now i have another problem. The empty rows are also sorted inside each group in a way I dont want. Each group should always have the not empty row at the top.

If I have this table, for example:

A - demo2 - related1 - related1
A - ______- related2 - related2
A - ______- related3 - related3
B - demo1- related1 - related1
B - ______- related2 - related2
B - ______- related3 - related3


I am grouping it by the first column (in this example).
Ordering it by the 2nd column should result in this: (demo1 < demo2)

B - demo1- related1 - related1
B - ______- related2 - related2
B - ______- related2 - related2
A - demo2 - related1 - related1
A - ______- related2 - related2
A - ______- related2 - related2

But currently, I have this kind of result: (as it order also the empty inside each group)

B - ______- related3 - related3
B - ______- related2 - related2
B - demo1- related1 - related1
A - ______- related2 - related2
A - ______- related3 - related3
A - demo2 - related1 - related1

I have tried to solve it with a code i saw here:
http://datatables.net/forums/discussion/4025/sorting-to-ignore-empty-cells/p1

But now it doesn't do anything when i try to sort the columsn i defined as "mystring". Only after sorting first by the right side columns and then doing it with the left side ones.

In my case this is the code i'm using (if nothing is wrong):

[code]
jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
var retVal;
x = $.trim(x);
y = $.trim(y);

if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= 1;
else if (y == "" || y == " ") retVal= -1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1

return retVal;
}
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
var retVal;
x = $.trim(x);
y = $.trim(y);

if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= -1;
else if (y == "" || y == " ") retVal= 1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1

return retVal;
}

var options = {
"aoColumns": [
null,
null,
{ "sType" : "mystring" },
{ "sType" : "mystring" },
{ "sType" : "mystring" },
{ "sType" : "mystring" },
{ "sType" : "mystring" },
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
oLanguage: {
"oPaginate": {
"sNext": ">",
"sPrevious": "<",
}
}
};
[/code]

Am I doing anything wrong?

Is it possible what I'm looking for?
This discussion has been closed.