Can I establishing order (on server-side) when use fileupload ?
Can I establishing order (on server-side) when use fileupload ?
Hi Allan,
When used fileuplod, you get files (on AJAX call) that come in order by ID on table (asc orden i think). Can be change this order in server side or in ajax call?. I´m working in standalone, that means that i not use table , therefore i can't to use methods that apply on table, but I need to establishing an order on base of the field ('es_un`).
If there are any way to establishing this order on fileuplod (on server side) please tell me know.
Any idea?
Thank you in advance!
Eduardo
- Related server-side code -
...
Editor::inst( $db, 'chef_recomd' )
->fields(
Field::inst( 'site' )->validator( 'Validate::notEmpty' ),
Field::inst( 'id_lang' )->validator( 'Validate::notEmpty' ),
Field::inst( 'nombre' )->validator( 'Validate::notEmpty' ),
Field::inst( 'condimentos' ),
Field::inst( 'es_un' )->validator( 'Validate::notEmpty' ),
Field::inst( 'alergeno' )->validator( 'Validate::notEmpty' ),
Field::inst( 'precio' )->validator( 'Validate::numeric' ),
Field::inst( 'prec_terraza' )->validator( 'Validate::numeric' ),
Field::inst( 'nota_item' ),
Field::inst( 'image' )
->setFormatter( 'Format::nullEmpty' )
->upload(
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' )
->db( 'files_chef_recomd', 'id', array(
'site' =>$site,
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path_thumb1' => '',
'sys_path_thumb1' => '',
) )
// for upload file
->where( function ( $q ) use ( $site ) {
$q->where( 'site', $site );
} )
),
...
->where( 'site', $site)
->process( $_POST )
->json();
This question has an accepted answers - jump to answer
Answers
Currently no - there isn't an option for that in the libraries. However, you can easily add one in the
Upload.php
file. Specifically in thedata
public method there is:You can add
->order( ... )
into that chain to add an order by clause to the SQL statement.Allan
Hi Allan,
I´ve to add line (see below) but it to do nothing, what I doing wrong?
Also, I understand that the field must to belong to file table, but I could refer a field of another table? (field that not on file table)
Thank you!
Eduardo
That looks like all that should be needed. Perhaps enable the debug mode by adding
->debug( true )
just before the->process(...)
method in your main Editor PHP configuration. That will show the SQL that is being executed for each request in the returned JSON.If you make the query into a Join, then yes, you could do that.
Allan
Hi Allan,
Congrats for your API and your help, each day I learn more about it.
Debug and my opinion : it look that take order() and is included on SQL sentence (see below), but the JSON output is not the wished ( is the same). I means, with order() JSON output should be 845, 843, 846, 844 (diferent output).. right?
NOTE: order used on this debug:
->order('filesize ASC');
Thank you!
Eduardo
Ah yes - the trick here is that the file information is in an object, not an array. And objects inherently have no order (looking at the one above, it looks like whatever serialised it for output ordered by key).
What I think you'd actually need to do is take the
files
object and use$.map
or similar to convert it to be an array and the sort it as required. The->order()
method on the server-side isn't actually going to be of any help in this case. Sorry about that!Allan
Hi Allan,
None problem, always is very interesting your comments.
Ok, now I understand.
Then, only on data [] ( array on JSON output) can be apply order() on server-side?. The current API has this method "order() on data[]" or also I must be add?
Thank you!
Eduardo
That is correct. Although to a large extent, that is actually irrelevant itself since DataTables will sort the data in the
data
array itself.To get ordered file information you could use
ajax.json()
to get the JSON object returned by the server, then use$.map()
on itsfiles
object to convert the objects into arrays and sort them. Its a bit of a pain, but that's the only way I see of doing that.Thanks,
Allan
Thank you for help me to resolve this question.
Greetings,
Eduardo