Duplicate selected field only

Duplicate selected field only

misteammisteam Posts: 48Questions: 17Answers: 0
edited December 2019 in Buttons

Hi!I would like to ask if it is possible for the duplicate function to replicate only a selected fields.
I'd like to duplicate the fields that are inside the box and leave the rest blank or empty.

Answers

  • misteammisteam Posts: 48Questions: 17Answers: 0
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Yep, you just need to set the specific fields, or if you've set them all, just clear the ones you don't want. That duplicate button is going to be one of yours, it's not a pre-supplied button, so it's something you'll need to change.

    Colin

  • misteammisteam Posts: 48Questions: 17Answers: 0

    Hi Sir, do you have an example for this?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Can you modify this to show what you have so far, please? As I said, we don't supply a duplicate button, so we need to see what you have first.

    Colin

  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

    Hi,

    I need help with this topic please.
    I'm working on a project with 3 different editor functions, one to insert, one to edit and one to duplicate.

    Insert:

    Edit (Field_1,Field_2,Field_5 and Field_6 as "type":'readonly',):

    Duplicate (Field_1,Field_2,Field_4,Field_5 and Field_6 as "type":'readonly',):

    Is it possible that the remaining fields do not load the recorded data, just load the options like the insert?
    I need to duplicate only the first 6 fields and force the rest to be filled out.

    http://test.qualportal.com/

    Best Regards
    João

  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

    Hi,

    Solved.
    I used the .setValue in the fields that I want to be filled in again.

    Best Regards
    João

  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

    Hi,

    Still working on this topic.
    I have a date field in which when I insert a new line it automatically records the insertion date (hidden field).
    When duplicating the line, I need to record the date of the duplication and not the initial insertion.
    I already have the function to duplicate according to what I want, but I need the date field to be default with the current date so that I can make it hidden.

    buttons: [
                { extend: 'create', editor: insert },
                { extend: 'edit',   editor: edit },
                {
                    extend: "selected",
                    text: 'Duplicate',
                    action: function ( e, dt, node, config ) {
                        // Start in edit mode, and then change to create
                        duplicate
                            .edit( table.rows( {selected: true} ).indexes(), {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                                                    .set( 'date', "" )
                                                    .set( 'field_7', "" )
                                                    .set( 'field_8', "" )
                                                    .set( 'field_9', "" )
                            .mode( 'create', "" );
                    }
                },
                { extend: 'remove', editor: insert }
            ]
    

    I'm already using this feature when inserting a new line:

    fields: [
                {
                 //"label": "Data:",
                 "name": "date",
                 "type": "datetime",
                 "def":  function () { return new Date(); },
                 "format": "YYYY-MM-DD",
                 "attr": { hidden:true}
                },
    

    I still can't fully understand the .set syntax
    It's possible? Can you help me please?

    Best Regards
    João

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This example should help, it's doing something very similar to you. There, the age is being set to '99' for the duplicated rows - you would do something similar for your hidden date field.

    Colin

  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

    Hi Colin,

    Thanks for the quick response.
    The difficulty lies in associating the return new Date() function with .set(date).

    Something like:

    action: function ( e, dt, node, config ) {
                        // Start in edit mode, and then change to create
                        duplicate
                            .edit( table.rows( {selected: true} ).indexes(), {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                .set( 'date', "" ) .def:  function () { return new Date(); },
                .set( 'field_7', "" )
                .set( 'field_8', "" )
                .set( 'field_9', "" )
                            .mode( 'create', "" );
                    }
    

    Is this possible?

    Best Regards
    João

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You would calculate the date you want first, or just do it in the set() function, something like this:

    action: function(e, dt, node, config) {
      // Get the date in the format you want
      let yourDate = new Date();
      
      // Start in edit mode, and then change to create
      editor
        .edit(table.rows({ selected: true }).indexes(), {
          title: 'Duplicate record',
          buttons: 'Create from existing'
        })
        .mode('create').set('date', yourDate);
    }
    

    Colin

  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

    Hi Colin,

    Thank you for your help. Working as intended.

    Best Regards
    João

Sign In or Register to comment.