Expanding all child rows from button - Page 2

Expanding all child rows from button

2»

Answers

  • kthorngrenkthorngren Posts: 21,450Questions: 26Answers: 4,975
    edited July 2023

    The example uses the rowData variable Allan used to get the row data:

    function createChild_1(row, showChildren) {
        //parent table data
        var rowData = row.data();
      
        var salespersonGroupingNumber = rowData.returnedSalespersonGroupNumber;
    

    You can then do something like this:

    ajax: {
            type: 'POST',
            url: 'BudgetReporting/getBudgetReporting_CustomerProductsData.php',
             data: {salespersonGroupingNumber: salespersonGroupingNumber,
                                       // Assumes you set the variable `customerNumber` same as `salespersonGroupingNumber` above
                                       customerNumber: customerNumber
                                      },
                        },
    

    Or you can skip setting the variable and do this:

    ajax: {
            type: 'POST',
            url: 'BudgetReporting/getBudgetReporting_CustomerProductsData.php',
             data: {salespersonGroupingNumber: rowData.returnedSalespersonGroupNumber,
                                       customerNumber: rowData.customerNumber
                                      },
                        },
    

    Also, as Allan mentioned, you don't need to set the child table id unless you are using it for some other purpose not shown in your test cases.

    Kevin

  • bbrindzabbrindza Posts: 316Questions: 73Answers: 1

    Kevin and Alan,

    I got it to work based off of Alan's bin example. Your suggestion where helpful :) .

    Last piece of the puzzle which I trust should be a simple one for you gurus.

    I also have a DataTable editor that I need to add in at the final child 3 .

    When I add it in a receive error as shown in my bin example. How can I get this to work?

    This was my original table look with the old script. The Next Year Budget row is the inline Editor

    When I comment out the inline row code it works, but when I out it back in it fails .

    See my latest bin. https://live.datatables.net/qagisada/10/edit

    The formatting may be a little funky , because I don't have al my css in here

       salespersonBillTo_editor = new $.fn.dataTable.Editor( {
             ajax: {
                     type: 'POST',
                     url: 'BudgetReporting/ssp_BudgetData.php',
                     data: { locationCode: rowData.locationCode,  
                             salespersonGroupingNumber: rowData.returnedSalespersonGroupNumber,
                             customerNumber: rowData.customerNumber,
                             productNumber: rowData.productNumber
                      },
                  },
    
            table: '#salespersonBillTo_budgetRows_' + rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber,
          
            formOptions: { inline: { onBlur: 'submit' } },
            fields: [
                            {
                            //  label: 'January Budget:',
                            name:  'BD$01',
                            },
                            {name:  'BD$02'},
                            {name:  'BD$03'},
                            {name:  'BD$04'},
                            {name:  'BD$05'},
                            {name:  'BD$06'},
                            {name:  'BD$07'},
                            {name:  'BD$08'},
                            {name:  'BD$09'},
                            {name:  'BD$10'},
                            {name:  'BD$11'},
                            {name:  'BD$12'},
                          ]
             } );
      
            // Set inline cell as selected to immediately start typing in new value          
             salespersonBillTo_editor.on('open', function () { 
                $('div.DTE input')[0].select();
            });
                
    //  // Child row DataTable configuration, always passes the parent row's id to server
    //  salespersonBillTo_childTable3
    //      .DataTable({
    //          createdRow: function ( row, data, index ) {
    //                $('td', row).eq(1).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_janBudget');
    //                $('td', row).eq(2).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_febBudget');
    //                $('td', row).eq(3).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_marBudget');
    //                $('td', row).eq(4).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_aprBudget');
    //                $('td', row).eq(5).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_mayBudget');
    //                $('td', row).eq(6).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_juneBudget');
    //                $('td', row).eq(7).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_julyBudget');
    //                $('td', row).eq(8).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_augBudget');
    //                $('td', row).eq(9).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_septBudget');
    //                $('td', row).eq(10).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_octBudget');
    //                $('td', row).eq(11).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_novBudget');
    //                $('td', row).eq(12).attr('id', rowData.locationCode + '-' + rowData.customerNumber + '-' + rowData.productNumber + '_decBudget');
    //             },
                    
    //             dom: 't',
    //             ajax: {
    //                      type: 'POST',
    //                  url: 'BudgetReporting/ssp_BudgetData.php',
    //                  data: { locationCode:rowData.locationCode,  
    //                              salespersonGroupingNumber: rowData.returnedSalespersonGroupNumber,
    //                              customerNumber: rowData.customerNumber,
    //                              productNumber: rowData.productNumber
    //                       },
    //                  },
    //               autoWidth: false,
    //               serverSide: true,
    //               order: [ 1, 'asc' ],
    //           keys: {
    //                  columns: ':not(:first-child, .markCompleteButton)',
    //                  keys: [ 9 ],
    //                  editor: salespersonBillTo_editor,
    //                  editOnFocus: true
    //           },
    //             columns: [
    //                         {
    //                             data: null,
    //                             searchable: false,
    //                             orderable: false,
    //                             className: 'budgetRowTitle',
    //                             render: function ( data, type, row ) {
    //                                  return '<td><b>Next Year Budget</b></td>';
    //                               }
    //                          },  
    
    //                           { data: 'BD$01', "width": "7%" },
    //                           { data: 'BD$02', "width": "7%" },
    //                         { data: 'BD$03', "width": "7%" },
    //                           { data: 'BD$04', "width": "7%" },
    //                         { data: 'BD$05', "width": "7%" },
    //                           { data: 'BD$06', "width": "7%" },
    //                         { data: 'BD$07', "width": "7%" },
    //                           { data: 'BD$08', "width": "7%" },
    //                         { data: 'BD$09', "width": "7%" },
    //                           { data: 'BD$10', "width": "7%" },
    //                         { data: 'BD$11', "width": "7%" },
    //                         { data: 'BD$12', "width": "7%" },
                               
    //                         {
    //                             data: null,
    //                             className: 'totalBudgetTD',
    //                             render: function(data, type, full, row ) {
    
    //                               var sum = 0;
    //                               for (var i=1 ; i<13 ; i++) {
    //                                 sum += parseFloat(full['BD$' + (i<10 ? '0' : '') + i]);
    //                                 sum = Math.round(sum * 10) / 10
    //                               }
                                   
    //                                 return '<span id="salespersonBillTo_totalBudgetSpan">'+sum+'</span>';
    //                             }
    //                         },
    
    //                           // ** Mark Completed Button
    //                         {
    //                             data: null,
    //                             searchable: false,
    //                             orderable: false,
    //                             className: 'markCompleteButton',
    //                             render: function ( data, type, full, meta ) {
                                       
    //                                  if( full.SYNCFL == 'N'){ 
    
    //                                        return '<button type="button" id="BR_CBT_markBudgetRecordCompletedButon_'+ full.PKLOC + full.PKGRP + full.PKCUST + full.PKPROD +'"class="btn btn-primary btn-xs" onclick="BR_CBT_showMarkBudgetRecordCompletedModal(\''+ full.PKLOC +'\', \''+ full.PKGRP +'\', \''+ full.PKCUST +'\', \''+ full.PKPROD +'\' )">Mark Completed</button>';
    //                                  }else{
    //                                         return '<button type="button" id="BR_CBT_markBudgetRecordCompletedButon_'+ full.PKLOC + full.PKGRP + full.PKCUST + full.PKPROD +'"class="unstyled-button" )">Mark Completed</button>';
    //                                  }
    //                              }
    //                          },  
    //             ],                                                                                                              
             
    //             columnDefs: [ 
    //                              { targets: "_all" , className: "text-center" },
    //                          //{ targets: 13, className: "text-center" },
    //                              { targets: "_all", orderable: false}
    //                          ],
                   
    //             select: {
    //                 style:    'os',
    //                 selector: 'td:first-child'
    //             },
    //      });
    

    Obi Wan Kenobi you my only hope.

  • kthorngrenkthorngren Posts: 21,450Questions: 26Answers: 4,975
    edited July 2023

    You need to load the Editor library. In the JS BIN page click Add Library, scroll to the bottom and select Editor. Move the added library down to load after jquery.js, etc. Like this:
    https://live.datatables.net/qagisada/11/edit

    Kevin

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    edited July 2023

    Exactly as you have done with your second code block there. That is making a POST Ajax call to BudgetReporting/getBudgetReporting_CustomerProductsData.php with two parameters passed to it.

    That script should return a standard {"data": [...]} JSON structure, with the rows to be displayed in that data parameter.

    Allan

    edit Sorry - this was out of date. I was reading the end of the last page when replying!

  • bbrindzabbrindza Posts: 316Questions: 73Answers: 1

    Kevin,

    I do have those in the bin after jQuery as well is in my script in my application as well as the bin

    In my previous thread I stated that it was working in my previous scripts before I changed to my script to emulated Alan's bin suggestion.

    DataTable Editor inline editor row does not show up in the table

    I do not get the error on my end that I see in the bin.

    I really not to get this resolved today or this project is a bust.

  • kthorngrenkthorngren Posts: 21,450Questions: 26Answers: 4,975

    I do have those in the bin after jQuery as well is in my script in my application as well as the bin

    Take a look at the test case again, all that is loaded is jquery and datatables:
    https://live.datatables.net/qagisada/10/edit

    I had to add Editor to remove the Uncaught TypeError: $.fn.dataTable.Editor is not a constructor error. Likely you will need to add select extension.

    I commented out the code to initialize the child 3 Datatable and get this error:

    DataTables warning: Non-table node initialisation (DIV). For more information about this error, please see http://datatables.net/tn/2

    You are using the variable salespersonBillTo_childTable3 to initialize Datatables which has div elements. You need to initialize against the table within this HTML. Maybe use the table ID.

    Kevin

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Answer ✓

    I've just been experimenting with the latest bin a bit and I picked up the same issue as Kevin. I used:

        row.child()
            .find('table.budgetDetailTable')
    

    to get the table you are trying to initialise as a DataTable. Updated bin: https://live.datatables.net/qagisada/13/edit .

    It will now give an Ajax error for ssp_BudgetData.php, but that is expected since there is no matching Ajax script on our server. It should get further on your own!

    Allan

  • bbrindzabbrindza Posts: 316Questions: 73Answers: 1

    Thank you all . It appears all is well. Hope this is the last post in this thread..

    Not to say that you may here from me on other topics. :)

Sign In or Register to comment.