How can I create multiple rows based on other selected rowss?

How can I create multiple rows based on other selected rowss?

NavernNavern Posts: 7Questions: 1Answers: 0
edited October 2017 in Free community support

Hello everyone!
I have a problem with DataTables Editor. I want to create multiple rows based on other selected rows!
Is it possible at all?
How can I duplicate multiple selected rows at the same time uses Editor?
please help me.

Answers

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    You'd need to use the multi-row API. Specifically use create() with the number of rows you want to create specified (i.e. the number of rows currently selected). Then use row().data() (probably inside rows().every()) and multiSet() to set the values for the fields.

    Allan

  • NavernNavern Posts: 7Questions: 1Answers: 0
    edited October 2017

    yes, but i want to enter different data for each selected row.

    Specifically use create() with the number of rows you want to create specified (i.e. the > number of rows currently selected)

    but, it just add the same data for each row..

    it should look like duplicate button, for each selected row.
    https://editor.datatables.net/examples/api/duplicateButton.html

    can you give me a sample code?
    thank you, Allan.

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin
    edited October 2017

    That's why I mentioned you'd need to use multiSet() inside rows().every() - you'd need to set the value from each row being duplicated.

    can you give me a sample code?

    Yes, this is something that would be covered under the support options.

    Thanks,
    Allan

  • NavernNavern Posts: 7Questions: 1Answers: 0

    Yes, this is something that would be covered under the support options.

    I bought a license, but it seems that the support period has already expired

  • NavernNavern Posts: 7Questions: 1Answers: 0

    Allan, can we just buy credit to cover that issue?

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Hi - yes indeed. The Quick Support 60 should be enough.

    I've just done a search to see what happened to any existing credits for your account, but I don't see an Editor license for your account. Was it purchased under another account?

    Thanks,
    Allan

  • NavernNavern Posts: 7Questions: 1Answers: 0
    edited October 2017

    Was it purchased under another account?

    yes, my another account is: Hubone

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Thanks - it looks like you have a single developer license which was purchased under that account. That doesn't come with any support credits I'm afraid.

    This is an interesting question though - I'll try to make some time to knock together an example, but I can't promise exactly when at the moment (bit of a support backlog!).

    Regards,
    Allan

  • NavernNavern Posts: 7Questions: 1Answers: 0

    Thank you, Allan.
    I just need a little kick.
    Perhaps you could give a hint how to improve my code for this.
    I need to open a new editing window for each selected row.
    After clicking the create button, this should add as many lines as it was selected, with different data.

    Here's an example:

    { text: 'Create Sales Order', action: function ( e, dt, node, config ) {
           //var data = table.rows({selected: true}).data();
           // var values = editor.edit(table.row( { selected: true } ).index(), false).val();
                        
            table.rows({selected: true}).every( function ( rowIdx, tableLoop, rowLoop ) {
                    var row = table.row( rowIdx );
                    //var data = this.data();
                    var values = editor.edit(row.index(), false).val();
        editor.title('Create Sales Order').buttons('Create New Order').create().set(values);
                                
            });     
                // if(data){
    
                             editor.on('onPreSubmit', function ( e, object ) {
                                 editor.off( 'onPreSubmit' ); 
                             });
                            
                            editor.on( 'submitComplete', function ( e, type, action ) {
                               editor.off( 'submitComplete' ); 
                            });
                            
                        
                        // }
                    }
    }
    
  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    I need to open a new editing window for each selected row.

    Ideally not. The multi-row editing should mean that you don't need to do that and only a single Ajax request would be needed to duplicate any number of rows.

    The issue with using edit() is that it is async and you can only submit one at a time. i.e. you would need to implement a queue. So get the list of rows to be duplicated and then duplicate them one at a time. That's perfectly do able, but it doesn't scale very well. The multi-row API would be more efficient, although the code is perhaps a little more complex (counterbalanced by the fact it wouldn't need a queue).

    Allan

  • NavernNavern Posts: 7Questions: 1Answers: 0

    Allan, I still don't understand how I can code this.
    Could you send a sample code?

    thanks

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Yes - the quick support package would cover the work involved.

    If that isn't an option, I'll try to make some free time to set up an example at some point next week, but I've got quite a backlog at the moment and can't promise that I'll get time to do it.

    Allan

  • hubonehubone Posts: 13Questions: 4Answers: 0

    hey, Allan.
    I bought the quick support package!
    can you help me now?

    so, that's what I want...

    I want to be able to select multiple lines and click that button which will launch a pop up that will allow me to enter some data for each line that I selected. (Each line individually based on what I enter for each line)

    I want to be able to enter new data in fields (These are new fields I want to be able to enter) all the other info from each line should be the same.

    It’s like split line feature but for multiple lines.

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Hi,

    Thanks for picking up the support package.

    This won't be what you want to hear I'm sorry to say, but what you are asking for is not supported by Editor. Specifically there is no way for it display individual data for each row that was selected. Each field will be shown only once - it will either show the value if it is the same for all fields, or a "this is a multi value field" message. You can see that happening in action on this page.

    The original question in this thread, as I understood it (perhaps incorrectly) was about duplicating existing rows with the same data for each row. As you noted above:

    it should look like duplicate button, for each selected row.
    https://editor.datatables.net/examples/api/duplicateButton.html

    That I can happily do, and if you can confirm that is what you want I'll provide an example of how to do that.

    If you want to show the individual values for each row to allow them to be edited before then as you described in your latest post, that is not something Editor can do and I'd happily refund your support payment.

    Regards,
    Allan

  • hubonehubone Posts: 13Questions: 4Answers: 0

    Hi Allan, Great regret, this isn't what we want to get and it doesn't solve our problem. We need exactly what I described above. Perhaps there is some other solution... If not, could you please refund my last support payment?

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    Yup - no problem. That's the refund issued. I'm sorry Editor can't do what you are looking for. From the original description I thought it would, but Editor's multi-row editing ability does not extend to showing the values for each row being edited, if the values are different.

    Regards,
    Allan

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0

    The example in the link you posted behaves properly in the UI, but I'm seeing that it just updates those records because the request sent to the server looks exactly like an edit. It makes a PUT request with {123123: {...}, 123124: {...}, ...}

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    The behaviour of that example has changed slightly in 1.7 as mode() can now be used as a setter - i.e. change the edit action into a create. So the key difference is that the action submitted is create.

    How do you have your ajax option set up?

    Allan

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    I see you have another thread on this topic where the Ajax configuration is shown. Let's continue the discussion there.

    Allan

This discussion has been closed.