Code Monkey home page Code Monkey logo

Comments (7)

n1crack avatar n1crack commented on May 24, 2024

I think it is not necessary.
You can add an option parameter to javascript to order any column you want.

https://datatables.net/reference/option/order

example :

$('#example').dataTable( {
    "order": [[ 3, 'asc' ], [ 1, 'asc' ]]
} );

from datatables.

n1crack avatar n1crack commented on May 24, 2024

Btw, that default part works only if there is no header info. Datatables is sending the header info to sort first column as default

from datatables.

andrejflorjancic avatar andrejflorjancic commented on May 24, 2024

I know well datatables option, but I want to have initial order completely different. I can not make that kind of order with columns in datatable.

from datatables.

n1crack avatar n1crack commented on May 24, 2024

https://gist.github.com/n1crack/7467a9a991369cb44b1e4d6af4933ac2
I made some changes for you in this gist. let me know about the results. You must add "order": [] to your javascript.

Still when the user sorts the table via clicking columns, it will be ignored.

from datatables.

andrejflorjancic avatar andrejflorjancic commented on May 24, 2024

No it is not good. If I have in order by something like "case when c.data_type = 'STRING' then 1 else 0 end, c.column_name", than I got error Unknown column 'c.data_type' in 'order clause''.

My solution:

.....
$query = preg_replace("/((?:[^()]+|(?R))+)/i", "", $query);
preg_match_all("/SELECT([\s\S]
?)((\s_)FROM(?![\s\S]_)))([\s\S]*?)/i", $query, $columns);
$this->hasOrderIn = count(preg_grep("/(order\s+by)\s+(.+)$/i", explode("\n", $query)));
$columns = $this->explode(",", $columns[1][0]);
.....

....
if ( ! is_array($dtorders))
{
return $this->hasOrderIn?"":$orders . $this->columns[0] . " asc"; // default
}
....

from datatables.

n1crack avatar n1crack commented on May 24, 2024

Nice one. ty. This will be added in the next patch.

from datatables.

andrejflorjancic avatar andrejflorjancic commented on May 24, 2024

Thx

from datatables.

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.