Got some problems with Editor plugin

Got some problems with Editor plugin

LTom93LTom93 Posts: 13Questions: 2Answers: 0
edited December 2015 in Editor

Hello,

  1. I want to be able to change / re-position the columns order.
    I tried to use colReorder(colReorder: true) - but it doesn't work!
  2. I'm using your colvis function to hide/show columns(configured it by DOM method, otherwise it doesn't work to me). I got 35 columns. I must have Show all / Hide all(check/uncheck). How can I do it?
  3. I'm trying to add a single upload image field to my table. I'm using your helper:
    https://editor.datatables.net/examples/advanced/upload.html
    But it doesn't work to me. You can check it on the live link below...
    I see the upload form, the image is uploaded to uploads folder, it's updated in the style_images table on database, I see the id number in the orders table in the column: style_image, but I get error:
    Uncaught TypeError: Cannot read property '3' of undefined
  4. After I have this upload function, if I export data to Excel, the image will follow? I must have the image inside the excel...

Can you please help me with this? and give me back the full code.
The link to the editor table is: http://www.orders.tomluz.co.il
You need to login first, details:
Username: Admin
Password: 123456

The link to the JS file(handling the editor script): http://www.orders.tomluz.co.il/cs/editor/custom/orders.js
My PHP code is:

Editor::inst( $db, 'orders', 'id' )
        ->fields(
            Field::inst( 'orders.id' ),
            Field::inst( 'orders.po_no' ),
            Field::inst( 'orders.order_date' ),
            Field::inst( 'orders.last_update' ),
            Field::inst( 'orders.supplier' ),
            Field::inst( 'orders.group' ),
            Field::inst( 'orders.style' ),
            Field::inst( 'orders.style_image' )
            ->setFormatter( 'Format::nullEmpty' )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
                ->db( 'style_images', 'style_images.id', array(
                    'file_name'    => Upload::DB_FILE_NAME,
                    'file_size'    => Upload::DB_FILE_SIZE,
                    'web_path'    => Upload::DB_WEB_PATH,
                    'system_path' => Upload::DB_SYSTEM_PATH
                ) )
                ->validator( function ( $file ) {
                    return $file['size'] >= 50000 ?
                        "Files must be smaller than 50K" :
                        null;
                } )
                ->allowedExtensions( [ 'png', 'jpg', 'gif' ], "Please upload an image" )
            ),
            Field::inst( 'orders.color' ),
            Field::inst( 'orders.destination' ),
            Field::inst( 'orders.customer' ),
            Field::inst( 'orders.container_number' ),
            Field::inst( 'orders.packing_details' ),
            Field::inst( 'orders.description' ),
            Field::inst( 'orders.factory_description' ),
            Field::inst( 'orders.samples_needed' ),
            Field::inst( 'orders.pairs_per_carton' )
                ->validator( 'Validate::notEmpty')
                ->validator( 'Validate::numeric'),
            Field::inst( 'orders.total_cartons' )
                ->validator( 'Validate::notEmpty' )
                ->validator( 'Validate::numeric' ),
            Field::inst( 'orders.fob' )
                ->validator( 'Validate::notEmpty' )
                ->validator( 'Validate::numeric' ),
            Field::inst( 'orders.taxes_cost' )
                ->validator( 'Validate::numeric' ),
            Field::inst( 'orders.shipping_costs' )
                ->validator( 'Validate::numeric' ),
            Field::inst( 'orders.shipping_date' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'orders.arrived_date' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'orders.so_number' ),
            Field::inst( 'orders.so_date' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'orders.start_ship' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'orders.cancel_date' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'orders.price' )
                ->validator( 'Validate::numeric' ),
            Field::inst( 'orders.container_received_date' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
            Field::inst( 'suppliers.name' ),
            Field::inst( 'customers.full_name' ),
            Field::inst( 'groups.title' ),
            Field::inst( 'colors.title' ),
            Field::inst( 'packing.title' ),
            Field::inst( 'styles.title' )
        )
            ->leftJoin( 'suppliers', 'orders.supplier', '=', 'suppliers.id' )
            ->leftJoin( 'groups', 'orders.group', '=', 'groups.id' )
            ->leftJoin( 'styles', 'orders.style', '=', 'styles.id' )
            ->leftJoin( 'colors', 'orders.color', '=', 'colors.id' )
            ->leftJoin( 'packing', 'orders.packing_details', '=', 'packing.id' )
            ->leftJoin( 'customers', 'orders.customer', '=', 'customers.id' )
            ->on('preCreate', function ( $editor, $values ) {
                $editor
                    ->field('orders.order_date')
                    ->setValue(date("Y-m-d", time()));
                $editor
                    ->field('orders.last_update')
                    ->setValue(date("Y-m-d H:i:s", time()));

                /* PO NO */

                $count = 0;
                $tmpl  = date("mdy", time());

                do {
                    $count++;
                    $sql = $this->db->query("SELECT `id` FROM `orders` WHERE `po_no`='{$tmpl}-{$count}'");
                } while($sql->num_rows());

                $editor
                    ->field('orders.po_no')
                    ->setValue($tmpl . '-' . $count);
            })
            ->on('preEdit', function ( $editor, $values ) {
                $editor
                    ->field('orders.last_update')
                    ->setValue(date("Y-m-d H:i:s", time()));
            })
        ->process( $_POST )
        ->json();

Thank you very much.

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi,

    Could you possibly confirm your location for me please? I've had notification from Stripe that the card used to purchase Editor with your account could potentially have been stolen - if that is your card you will want to get in touch with your bank immediately and cancel it.

    Allan

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Hi,

    Are you serious about this? I paid with my USA CC. I'm currently in Israel,
    I didn't see anything weird in my cc logs, I will contact them asap. Thanks.

    Can you please let me know if I can do anything to fix this. I would like to get your help about my questions.

    Thanks!

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Yup - sorry. Hope you can get it cleared up!

    I'll try to take a look at the issues above as soon as I can, but likely it will be next week now.

    After I have this upload function, if I export data to Excel, the image will follow? I must have the image inside the excel...

    There is no option to export images into Excel using Buttons at this time.

    Allan

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Yeah ok thank you.
    About the export image - there is an option to export the path of the image instead?

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Yes, you could use a renderer to do that:

    Allan

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Hi Allan,

    I have just fixed the problem with uploading a picture. It works.
    I need help with:
    1. I want to be able to change / re-position the columns order. I tried to use colReorder(colReorder: true) - but it doesn't work!
    2. I'm using your colvis function to hide/show columns(configured it by DOM method, otherwise it doesn't work to me). I got 35 columns. I must have Show all / Hide all(check/uncheck). How can I do it?
    3. After I have this upload function, if I export data to Excel, the image will follow? I must have the image inside the excel.

    Thanks.

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Hello Allan,

    Can you please help me with the 3 problems? I wrote them in the last message.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I want to be able to change / re-position the columns order. I tried to use colReorder(colReorder: true) - but it doesn't work!

    It doesn't look like you have the ColReorder extension installed on your page. This is a debug trace from your page.

    I'm using your colvis function to hide/show columns(configured it by DOM method, otherwise it doesn't work to me). I got 35 columns. I must have Show all / Hide all(check/uncheck). How can I do it?

    I would suggest using Buttons rather than ColVis which is no longer being actively maintained. Example.

    The documentation for the columnVisibility type describes how it can be used for show all / hide all functionality.

    I'm trying to add a single upload image field to my table

    I've just uploaded an image and it appears to work okay - I didn't see any errors.

    Allan

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    How can I export the image path? It doesen't work for me. I tried to use your examples but it wen't wrong... Can you please help me with the code? I gave me JS code above.

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Hi Allan,

    Can you help me please with my last message?

    How can I export the image path? It doesen't work for me. I tried to use your examples but it wen't wrong... Can you please help me with the code? I gave me JS code above.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Since you are already using a columns.render function for the display of the image:

                                render: function ( file_id ) {
                                    return file_id ?
                                        '<img src="'+table.file( 'style_images', file_id ).web_path+'"/>' :
                                        null;
                                },
    

    I would suggest using the orthogonal export approach that I linked to above - i.e. have the function return different data (the path) for the export and configure Buttons to export orthogonal data as shown in that example.

    Allan

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    How can I put 2 functions in the render? and how can I get the full path?
    Please send me the code, I can't do it by myself \=

  • LTom93LTom93 Posts: 13Questions: 2Answers: 0

    Help please?

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi,

    If you require me to do this work for you, I'd be happy to write up and example showing how this can be done under the Quick Support 60 option.

    You can't put two functions into the render, but you can put an if statement. Just do a conditional check to see if it is requesting the orthogonal data or not. If it is then return the web path without the image tags.

    Allan

This discussion has been closed.