The sorting column in failing on several forms, what do we look for to fix this?

The sorting column in failing on several forms, what do we look for to fix this?

koniahinkoniahin Posts: 186Questions: 39Answers: 7

We have been using the same sort code for some time and I see that it is failing on several forms, good on others.

In the .js file we have for the column:

{ name: "articles.rowOrder", data: "articles.rowOrder", className: "reorder no-inline", },

And sorting js:

  .on("postCreate postRemove", function() { table.ajax.reload(null, false); })
  .on("initCreate", function() { editor.field("articles.rowOrder").enable(); })
  .on("initEdit", function() { editor.field("articles.rowOrder").disable(); });

In the controller I copied in the code direct from the example page substituting the table and column names:

    // ROWORDER BLOCK

    ->on( 'preCreate', function ( $editor, $values ) {
        if (! $values['rowOrder']) {
            // If no value submitted, then use the max+1 as the new value
            $next = $editor->db()->sql('select IFNULL(MAX(rowOrder)+1, 1) as next FROM articles')->fetch();
            $editor->field('articles.rowOrder')->setValue($next['next']);
        }
        else {
            // On create update all the other records to make room for our new one
            $editor->db()
                ->query( 'update', 'articles' )
                ->set( 'rowOrder', 'rowOrder+1', false )
                ->where( 'rowOrder', $values['rowOrder'], '>=' )
                ->exec();
        }
    } )
    ->on( 'preRemove', function ( $editor, $id, $values ) {
        // On remove, the sequence needs to be updated to decrement all rows
        // beyond the deleted row. Get the current reading order by id (don't
        // use the submitted value in case of a multi-row delete).
        $order = $editor->db()
            ->select( 'articles', 'rowOrder', array('id' => $id) )
            ->fetch();

        $editor->db()
            ->query( 'update', 'articles' )
            ->set( 'rowOrder', 'rowOrder-1', false )
            ->where( 'rowOrder', $order['rowOrder'], '>' )
            ->exec();
    } )

    // ROWORDER BLOCK

What happens currently. When you drag the Sort column (last) it appears to respond but returns to the original position. The site is apache-restricted: To access the site:

www.smokeymo.xyz
username: guest
password: %guest%()

If you wish to access the form you will need to sign into your account or use a guest account:

email: uhavehighhopes@gmail.com
password: %guest%()

From the dashboard menu select DTE --> Public FAQ

Answers

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862
    edited August 2023

    Sounds like you are using RowReorder. The docs have this:

    Normally you will want this to be a sequential number! The data reorder can potentially confuse end users otherwise!

    Possibly you need to use orderFixed to make sure the sorting column for RowReorder is always first.

    Are you using a numeric index for the column used to order the table? If not then the order may not be as expected. Take a look at this example

    Kevin

  • koniahinkoniahin Posts: 186Questions: 39Answers: 7

    They are sequential however this is a view of data where the page_type = 'public-faq'. I have been doing this for a long time and it usually works. Did you look at the demo page and try reordering a couple items?

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862

    When reordering the Editor sends this edit request to the server:

    data[row_874][articles][rowOrder]: 6
    data[row_874][articles][metatitle]: 
    data[row_874][articles][metadesc]: 
    data[row_874][core-tab]: 
    data[row_874][metadata-tab]: 
    data[row_875][articles][rowOrder]: 7
    data[row_875][articles][metatitle]: 
    data[row_875][articles][metadesc]: 
    data[row_875][core-tab]: 
    data[row_875][metadata-tab]: 
    action: edit
    

    The request represents swapping two rows. However the server is responding with these errors:

    {
        "fieldErrors": [{
            "name": "articles.metatitle",
            "status": "This field is required."
        }, {
            "name": "articles.metadesc",
            "status": "This field is required."
        }, {
            "name": "articles.metatitle",
            "status": "This field is required."
        }, {
            "name": "articles.metadesc",
            "status": "This field is required."
        }],
        "data": []
    }
    

    Not sure why because they appear to be in the parameters sent. The articles.rowOrder field is not updated in the server and when the table is refreshed via draw() the server side processing request shows row_874 retains the original articles.rowOrder of 7 and row_875 retains the original articles.rowOrder of 6.

    Use the browser's network inspector to see the above. You server script will need to be debugged to learn why it is returning the fieldErrors.

    Kevin

  • allanallan Posts: 62,524Questions: 1Answers: 10,272 Site admin

    RowReorder will send only the changes values, as noted in rowReorder.formOptions. You can change that to be all value in the row with that option - e.g.:

    $('#myTable').DataTable( {
        rowReorder: {
            dataSrc: 'sequence',
            editor:  editor,
            formOptions: {
                submit: 'allIfChanged'
            }
        }
    } );
    

    It isn't clear to me yet why it thinks metatitle and friends have changed, but try that and see if it helps. If not I'll dig deeper.

    Allan

  • koniahinkoniahin Posts: 186Questions: 39Answers: 7

    I really don't understand the javascript, will pass that along to my partner. However, this does help.

    1) Sequential - before submitting the post I looked (command line mysql) at the table, id and reorder fields - found a couple duplicates, fixed them. I used an sql that resets reorder starting at 1 incrementing each row, leaving clean data.

    2) Seeing what you replied about meta- fields, I commented them out in the php and controller files. This did not help but removed some errors/warnings.

      {
        label: "Metadata",
        name: "metadata-tab",
        className: "dte-title  block",
      },
    

    This is not a database field, is only a note/header field placed at the top of a section using CSS to hide the input.

    3) I ran update queries to ensure that both metatitle and metadesc fields were all set to empty if NULL. No help, okay.

    4) Still getting an error something like 'metadesc is not defined' even though commented out. Scratching my head for a few seconds.

    5) Not comfortable with having potential administrators creating their own slug/alias, metatitle, and metadesc we/he created a function to generate meta data and slugs. I commented out the code in both the php/html file and controller for this form only and sorting works.

    I believe this gives us the pointer we need to solve the problem. This type of work is not my fortay. In Firefox sometimes I use Web Developer and the Console, not much more. Can you point me to the path in web developer to see what you see?

  • allanallan Posts: 62,524Questions: 1Answers: 10,272 Site admin

    I've just tried https://www.smokeymo.xyz/bin/public-faq and reordering by the last column appears to work okay as it is just now.

    data[row_874][articles][rowOrder]   "6"
    data[row_873][articles][rowOrder]   "7"
    action  "edit"
    

    is submitted, which looks good to me and reloading the page leaves the data in the new order.

    Allan

  • koniahinkoniahin Posts: 186Questions: 39Answers: 7
    edited August 2023

    Yes I commented out the metaGeneration code in both files. For reference,with article, blog posts and faq like this which might have its own page, what the code does is 3 things:

    1) It uses regex to create a people-friendly string out of the title
    2) Upon New, it copies the original title into the metatitle and metadesc fields.
    3) To avoid duplication it adds the ID to the beginning of the string something like:

    1234-oh-what-a-tangled-web-we-weave

    It's on us to figure this out now. Thx.

  • allanallan Posts: 62,524Questions: 1Answers: 10,272 Site admin

    Haha! Good to hear you are making progress with it :)

    Allan

Sign In or Register to comment.