We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42415
    • 115 Posts
    Adding Items To MIGXDB So They Don't Go To Bottom Of The List

    This is my scenario; I add items to MIGXDB by right clicking on an existing item and clicking 'Duplicate' then I edit the new item and click 'Done' when I want to save it.

    This is great for adding new items to the database when I want them to go to the bottom of the list.

    However, I now have over 12,000 items listed in my MIGXDB and I want to add more items so they are listed together with existing groups of items (not go to the last in the list)

    When I right click on an item the options given are as follows:
    Edit
    Duplicate
    Unpublish
    Remove

    What I want to do is have another option like 'Input above current item' or 'Input below current item' (just like the options you can get on a microsoft excel doc)

    This way when I add an item I can choose where it resides in MIGXDB.

    Is this possible?

    If yes, what must I do to configure MIGXDB to give me this option?

    This question has been answered by Bruno17. See the first response.

      • 4172
      • 5,888 Posts
      this is possible, but you would need some customization and custom-coding.
      Fist, you would need an additional field, where you can define the position of each item, name it 'pos'
      Then you would set the sortorder of the grid to this field.

      Then you have to create two new custom context-menue-items for add above and add below (some coding needed)
      Two new hidden fields in the form with the id of the old item and a value for where to add the new item (before or after)
      Then you will need a aftersave-hook-snippet, which would set the new positions of all items, depending on where you add the new item.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 42415
        • 115 Posts
        Quote from: Bruno17 at Jan 28, 2017, 08:39 AM
        this is possible, but you would need some customization and custom-coding.
        Fist, you would need an additional field, where you can define the position of each item, name it 'pos'
        Then you would set the sortorder of the grid to this field.

        Then you have to create two new custom context-menue-items for add above and add below (some coding needed)
        Two new hidden fields in the form with the id of the old item and a value for where to add the new item (before or after)
        Then you will need a aftersave-hook-snippet, which would set the new positions of all items, depending on where you add the new item.

        Hi Bruno,

        Thanks for the response smiley

        I think this is beyond my capabilities. I suppose I thought it could be done by just configuring a few fields without any coding required.

        Just wondering if anyone else has requested this?

        Is it possible to include this feature in any future MIGXDB upgrades?
          • 42415
          • 115 Posts
          Update!
          MIGX 2.11.0 beta3 is available on GitHub where you can add item before/after (Thanks Bruno smiley )
          https://github.com/Bruno17/MIGX/blob/master/_packages/migx-2.11.0-beta3.transport.zip

          So here is where I am at now, I got an issue loading my new schema (one integer field called 'pos' must be added to existing schema). Here is what I've done:

          I successfully updated to 2.11.0 beta3
          Then in Modx manager, in Setup/Upgrade I clicked on set up = success

          Next I follow this process:

          In migx management
          package manager>>package name (from xml table) = 'datequote'
          click custom prefix>>custom-prefix = modx_
          click create package
          click Xml schema & paste in schema>>click load schema>>click save schema
          click parse schema tab>>click parse schema
          click create tables>>click create tables

          However when I click load schema I am not getting a success message
          This is the schema I am trying to load (added 'pos'):

          <?xml version="1.0" encoding="UTF-8"?>
          <model package="datequote" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
          <object class="DateQuote" table="datequote" extends="xPDOSimpleObject">
          <field key="quote" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="author" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="topic" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="birthday" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="month" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
          <field key="date" dbtype="int" precision="10" phptype="string" null="false" default=""/>
          <field key="pos" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
          <field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
          <field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
          <field key="editedon" dbtype="datetime" phptype="datetime" null="true"/>
          <field key="editedby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
          <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
          <field key="deletedon" dbtype="datetime" phptype="datetime" null="false" />
          <field key="deletedby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
          <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
          <field key="publishedon" dbtype="datetime" phptype="datetime" null="false" />
          <field key="publishedby" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
          <aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign"/>
          <aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign"/>
          </object>
          </model>

          In MIGXDB I now have the option to 'addbefore' and 'addafter' when I right click on a MIGX item, but it is saving to the end at the moment.

          Also, if I type in 'pos' to getlist defaultsort then none of the items from mysql are loading in MIGX, so I have left getlist defaultsort blank (no input)

          So the problem I think is an issue with my schema or how I am loading it.
          Am I supposed to load the new schema in PhpAdmin first? Or am I supposed to update the schema in Migx manager?

          Any advice you could give to make this work?
          • discuss.answer
            • 4172
            • 5,888 Posts
            Seems to me, the pos - field is missing somewhere.

            with modx_ as table-prefix, you don't have a custom-prefix. That's the default prefix. So you don't need to fill this field.

            and if you have allready an existing package (core/components/yourpackage - directory) you don't want 'click create package' again.

            just load the schema, add your new fields to the schema, save the schema, click 'Add fields' (this should parse the schema and recreate the map-files and add the new fields to your tables) - done.

            Did you check, if the new field was added to your table (and the map-file)?

            Also with a int-field, you should have default="0", not default=""

            <field key="pos" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>


            [ed. note: Bruno17 last edited this post 7 years, 1 month ago.]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 42415
              • 115 Posts
              Quote from: Bruno17 at Feb 24, 2017, 07:47 AM
              Seems to me, the pos - field is missing somewhere.

              with modx_ as table-prefix, you don't have a custom-prefix. That's the default prefix. So you don't need to fill this field.

              and if you have allready an existing package (core/components/yourpackage - directory) you don't want 'click create package' again.

              just load the schema, add your new fields to the schema, save the schema, click 'Add fields' (this should parse the schema and recreate the map-files and add the new fields to your tables) - done.

              Did you check, if the new field was added to your table (and the map-file)?

              Also with a int-field, you should have default="0", not default=""

              <field key="pos" dbtype="int" precision="10" phptype="integer" null="false" default="0">


              </field>


              Hi Bruno,


              I follow your above instructions and it worked perfectly smiley

              The schema loaded, i checked it in PhpMyAdmin and the 'pos' field is there

              Thank you so much

              The add after feature functions just fine.

              I do have one further question about the order each item will display (next post)
                • 42415
                • 115 Posts
                Hi Bruno,

                I want to ask you about how the list items in MIGXDB will display on the front end.

                As you can see from the image below I can now add items below an existing item.



                The first listing is no longer on the first page, if I change the number to 100 items per page I can see that the first item (number 1) is on page 122 (see below image at bottom of page).



                What I'm wondering is in what order these items will display on the front end.

                For example I use the following code that updates one page every day (it displays all items from the date of today, so every day it updates):

                [[!migxLoopCollection?
                &packageName=`datequote`
                &classname=`DateQuote`
                &selectfields=`id,quote,author,topic,birthday`
                &where=`{"date":"[[!now:date=`%d`]]","month":"[[!now:date=`%B`]]"}`
                &tpl=`myTpl`
                ]]


                myTpl:

                <p style="font-size: 18px; color:#000000; font-weight: bold;">[[+quote]]</p>
                <p style="font-size: 14px; color:#800000;">[[+author]]<br>
                [[+topic]]<br>
                Born on: [[+birthday]]</p><br>


                now:

                <?php
                return time();


                For the 2 items I added below (addAfter) at the start of the list (after No 1 ... No's 15424 and 15426 see 1st image) they both share the same name Hugh Hefnor.

                I'm wondering how will the list display on the front end; Will it go:

                1
                15424
                15426
                2
                3
                4
                etc......

                or will it display:

                1
                2
                3
                4
                5
                6
                15424
                15426

                The reason I ask is I want each group to display together, in this case Hugh Hefnor quotes No 1, No 15424, No 15426, then go onto No 2, No 3, No 4.......

                Because I started saving these items on 9th April last year I have to wait until next April 9th 2017 to see how the item list renders on the front end page now.

                  • 4172
                  • 5,888 Posts
                  if you want to order by pos, use:

                  &sortConfig=`[{"sortby":"pos"}]`
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 42415
                    • 115 Posts
                    Thanks Bruno, I added that line and it is working ok smiley