Button Problem with a each function
Button Problem with a each function
Andreas S.
Posts: 208Questions: 74Answers: 4
in Buttons
I want create custom buttons, that stored in a database. I get the text Information with an $.get or $.ajex function from the database and add the button information with an $.each loop and the push() function in a array. The array has some object inside, but the buttons would not shown in the Button collection or as buttons outside a collection.
Have someone a idea what is here wrong with my code?
Code with Button collection:
let dtButtons = [];
let yrButtons = [];
$.get( "{{ route( 'admin.para-base-times.getBaseYears' ) }}", function( data ) {
$.each( data, function( i, val ) {
yrButtons.push( {
text: val.year,
className: 'border border-dark btn-sm ml-0 mb-1'
} );
} );
} );
dtButtons.push( {
extend: 'collection',
text: 'Year',
className: 'btn-sm btn-White',
collectionLayout: 'two-column auto-width',
autoclose: true,
buttons: yrButtons
} );
Code without Button collection:
let dtButtons = [];
$.get( "{{ route( 'admin.para-base-times.getBaseYears' ) }}", function( data ) {
$.each( data, function( i, val ) {
dtButtons.push( {
text: val.year,
className: 'border border-dark btn-sm ml-0 mb-1'
} );
} );
} );
This discussion has been closed.
Answers
I'm not seeing a call to
button().add()
which would add it to a collection or into the DOM. Are you calling that elsewhere?Colin
I think, i do that in the
datatable()
. Here my full code:Andreas
Ah, you're adding
dtButtons
in the table initialisation. It looks like it should work. Are you able to create a test case, please, so we can debug. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.Cheers,
Colin
My debug upload: https://debug.datatables.net/uverit
Andreas
Colin asked for a test case so we can help debug your code not the debugger trace.
Kevin
Send pm to colin for the test case