Custom button to edit multiple rows
Custom button to edit multiple rows
Hello,
i need a custom button which edit the selected rows. I tried it with multiset, but i didn't get an solution...
'''js
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{
// extend: 'selectedSingle',
text: 'Alter + 10' ,
action: function ( e, dt, node, config ) {
// Immediately add `250` to the value of the salary and submit
editor
//.field('sql_alter_1').multiSet('row_1', 1)
.multiset( 'sql_alter_1', 1 )
// .edit( table.row( { selected: true } ).index() ) //, false
// .set( 'sql_alter_1', (editor.get( 'sql_alter_1' )*1) + 1 )
.submit();
}
} ,
{ extend: 'remove', editor: editor }
]
} );
'''
Does i need a loop? I have no idea...
Is there anywhere an example (example for a loop in buttons)- i didn't find something.
Thx for your help,
Thomas
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
'''
text: 'Alter + 10' ,
action: function ( e, dt, node, config ) {
//alert( table.rows('.selected').data().length +' row(s) selected' );
'''
This is my Script - The editor doesn't work correct, because there are to many sql request in a short time.
If i use the '''alert''' Button - it works.
I think there must be a better way - has somebody an idea?
Thx,
Thomas
What is it that you want the button to do? I know you want to edit multiple values - but alter them in what way?
Allan
Hello Allan,
I like that the user can select multipe rows and if the user press the button, this rows will get a new value in one cell.
In this table all orders for the user are shown. The orders have all the status "NEW - ID is 1", if the user press the button the next status is "RUN - ID is 2".
In my PHP-SQL-Script for this table I made an where-clause, so that in this table will shown only datas with the status 1 and the user will only the orders with the status new.
Table:
ID | Order | Date | Status
So the user can handle it really easy.
Got it - thanks. So the value to set for the cell is not common to all rows being edited - but rather the value is dependent upon the data in the rest of the row's data. In which case, I'm afraid a loop is the only way to do it at the moment.
Being able to provide a function that will do that loop for you is a nice idea though - thanks for the suggestion - I will look into that.
Regards,
Allan
Hello Allan,
I think we are thinking the same. For beeing sure...
Table
Selected rows 1, 3 and 4 -> User press the button for the next status
Hoping now everything is clear.
Thanks a lot for your support and i am looking forward for your solution.
Regards
Thomas
In your example above, the
Status
column has been updated to a common value for the selected rows. So you could simply useeditor.field( 'Status' ).val( 2 );
(or similar) to set the value (since it is a common value).It is where there is no common value that you would have to use a loop.
Allan
Hello,
and this doesn't work with a custom button.
That is my problem.
And I think there must be an easy way. Because the user want it easy.
It was already a discussion:
https://datatables.net/forums/discussion/27973/update-multiple-rows-using-customised-control-button
The thread you linked to was before Editor 1.5 was released (the version which added multi-row editing).
The code you have above should work - although I don't see where the
row
variable is being defined? I think you might want to try:If that doesn't work, can you link to a test page showing the issue.
Allan
Works perfect. Thanks a lot.
Could be nice example on your page...
Thx
Thomas