select row with fix column not working can not read property repalce of undefined

select row with fix column not working can not read property repalce of undefined

dk_devdk_dev Posts: 6Questions: 1Answers: 0
edited May 2021 in FixedColumns

Hi All,
I am new to data table community,
I am using fix column with select rows with server side implementation,
whenever i select any scrollable column i am able to get row id which i used for page total and column total
but when i select any fixed column in my case it is right side 2 columns it gives error as -
Cannot read property 'replace' of undefined

from my understanding fix column is not able to return particular row id when i click on it,

Error Message -
http://mail.datatables.net/forums/uploads/editor/8q/eoao67zvtu2d.png
http://mail.datatables.net/forums/uploads/editor/ay/puchjb3p8jdu.png

I am using onclick 'tr'to get triggered row value and using following code -

$('#sort_table_id tbody').on('click', 'tr', function ()
{
  var id = this.id;
  var index = $.inArray(id, selected);

  if ( index === -1 )
    selected.push( id );
  else
    selected.splice( index, 1 );

  col_pos_carats = 4;
 
  //get selected row sum
    var get_current_selected_cts        = (table.column( col_pos_carats).visible()  === true  ?
    $(this).find("td:eq("+col_pos_carats+")").html().replace(/\$|,/g, '') : 0);
 
    if($(this).hasClass('selected')) // set from row callback
    {
      selected_cnt            -= +1;
      selected_cts_sum        -= +get_current_select
    }
    else
    {
      selected_cnt            += +1;
      selected_cts_sum        += +get_current_selected_cts;
    }
 
    $('#sum_cts_selected').html(Math.round(selected_cts_sum * 100) / 100);
    $(this).toggleClass('selected');
});

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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

  • dk_devdk_dev Posts: 6Questions: 1Answers: 0

    Hi,
    I have tried for following test case but it was not adding up salary when we clicked on it, but when we click on any fixed column (in this case left side 2 columns) that replace of undefined error is coming.

    http://live.datatables.net/mazetihi/1/edit

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited May 2021 Answer ✓

    I see, you're parsing the HTML to get the salary, but that column isn't present when you click on the overlay for the fixed column. It would be best to use the DataTables API to get the data, with row().data(), and use that for your sums. See an updated test case here: http://live.datatables.net/mazetihi/2/edit

    Colin

  • dk_devdk_dev Posts: 6Questions: 1Answers: 0
    edited May 2021

    Hi,

    Thank you Colin, this is super helpful, it solved my issue,
    thank you for providing super quick solution !!

    just one more addition when we fix column on left or right footer-callback was not able to recall again which lead to not updating any footer total for those fix columns.
    how do i re-trigger footer-callback for fix columns ?

    i have only fixed right column of salary and we render page total for first page but for 2nd page or any change in table (if we implement server side with individual column searching which change dataset present in table OR we change page length from 50 to 100) page total for fix column is not updating.

    test case -
    http://live.datatables.net/mazetihi/3/edit

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

    I took a look, but the footer appears to be updating for me. Could you provide step-by-step instructions, please, on how to reproduce the error.

    Colin

  • dk_devdk_dev Posts: 6Questions: 1Answers: 0

    Hi Colin
    Steps for reproduce error -
    1. Table load with dataset
    2. Footer-callback calculate all columns total for each selected columns
    3. If We have fixed any column which contain any total it gets loaded properly on initial load.in first footer-callback.
    3. If we navigate to 2nd or next page footer-callback triggers for new total of new page,
    4. All columns footer gets updated with new respective total
    5. But For Fixed-Left or Right Column total doesn't get updated as its overlay to original table.

    http://live.datatables.net/mazetihi/3/edit

    in above example if we navigate through pages salary footer total doesn't get updated with respective page total as salary column is Fixed-Right.

    This is with if we navigate to next pages, but this arises when there is individual column searching/filtering On as table redraws for filtered query and footer-callback trigger for any selected column total.

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

    The FixedColumn extension overlays the table, but it seems column().footer() doesn't factor this in when returning the node. You can compensate for that by writing directly into the DOM element. It also needs to be done in initComplete as footerCallback doesn't have an effect on the first draw.

    See updated test case here: http://live.datatables.net/mazetihi/6/edit

    Colin

  • dk_devdk_dev Posts: 6Questions: 1Answers: 0

    Hi Colin,
    Sorry for delayed update,
    Thanks for your alternative solution on freeze column with select API. the solution seems to work with single column, how do multiple column total with freeze should work ?
    any ideas, suggestions are appreciated !

    Once again Thank you for your wonderful help !

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

    The example I posted before has two frozen columns, so I'm not too clear about your last comment. Please can you update my example so that we can see the problem.

    Cheers,

    Colin

Sign In or Register to comment.