Code Monkey home page Code Monkey logo

Comments (6)

Holt59 avatar Holt59 commented on August 19, 2024

I don't really understand what you want to do... You would like to be able to sort specific columns without having to specify true/false for all the others?

from datatable.

julesbl avatar julesbl commented on August 19, 2024

Hi Mikaël
I'm obviously not making the idea clear.
At the moment config.sort tends to be like [true, false, true, true etc..]

This does not help with tables like this

		<tr>
			<th>stallion</th>
			<th>runners</th>
			<th colspan="2">winners</th>
			<th>w/r</th>
			<th>starts</th>
			<th>wins</th>
			<th colspan="2">stakes </th>
			<th colspan="2">progeny  earnings</th>
		</tr>

with complex strings like £1,500,000 in the sort columns for progeny earnings which need to be sorted out by a function.

What I was suggesting is the ability to put an integer in the column position to indicate a sort column, not just true, and also the capability of and integer and a function for processing the data to make it sortable.
config.sort = [false, true, true, 4, false, false, false, {column: 9, func: price_sort,}];
would make 'w/r' sort on column 4 and 'progeny earnings' would sort on column 9 using the function price_sort to implement the sorting function for data like £1,500,000

Hope that is clearer.

Jules

from datatable.

Holt59 avatar Holt59 commented on August 19, 2024

@julesbl I have to admit that I am not even sure of all the features available in this plugin anymore (the documentation is way outdated... ), but I think that what you want is already implemented in the following way:

config.sort = {
    0: false,
    1: true,
    2: true,
    4: true,
    5: false,
    6: false,
    9: number_sort
};

from datatable.

julesbl avatar julesbl commented on August 19, 2024

Works very well when there are the same number of header columns as data columns, where it comes unstuck at the moment is when they differ, as in this case 8 header cols and 11 data columns, there is no way to tell the sort function to work on anything but column 7

from datatable.

Holt59 avatar Holt59 commented on August 19, 2024

@julesbl The index/keys of the array/object you use for the sort options are match with the <th> elements (the nth element of config.sort will be used for the nth <th>). If either:

  • the number of <th> does not match the number of columns;
  • the <th> have different index than columns;

...you can use an Object instead of an Array, such as the one in my previous answer, to specify on which column each <th> should sort.

Small example:

If your <th> are like this:

<tr>
  <th>TH 1</th>
  <th colspan="2">TH 2</th>
  <th>TH 3</th>
  <th colspan="2">TH 4</th>
</tr>

Then:

[true, true, true, true];

...will make TH 1 sort the first column, TH 2 the second, TH 3 the third, and so on...

But:

{
    0: true,
    1: true,
    3: true,
    4: true
} 

...will make TH 1 sort the first, TH 2 sort the second, TH 3 sort the fourth and TH 4 the fifth.

from datatable.

julesbl avatar julesbl commented on August 19, 2024

Thanks, had not twigged about the object

from datatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.