Possible bug: DataTables 2.1.7 datatables.js - function _fnStringToCss( s ) - line 5604

Possible bug: DataTables 2.1.7 datatables.js - function _fnStringToCss( s ) - line 5604

rsiegel64rsiegel64 Posts: 5Questions: 2Answers: 0

Description of problem: _fnStringToCss(s) sometimes being sent an object, throwing an s.match not a function error. Bug either in the sender or this function. Locally, I fixed by replacing s.match(/\d$/) with s.toString().match(/\d$/), which works for me.

function _fnStringToCss( s )
{
    if ( s === null ) {
        return '0px';
    }

    if ( typeof s == 'number' ) {
        return s < 0 ?
            '0px' :
            s+'px';
    }

    // Check it has a unit character already
   return s.match(/\d$/) ?
      s + 'px' :
      s;
}

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Can you post a link to a test case showing the issue please? I'm not sure under what conditions that would happen, so it would be instructive to see an example.

    Allan

  • rsiegel64rsiegel64 Posts: 5Questions: 2Answers: 0

    I can post code snippets. Here is the code used.

       <script type="text/javascript" src="Scripts/datatables.js"></script>
       <link rel="Stylesheet" type="text/css" href="css/datatables.min.css" />
    
       
        $(document).ready(function () {
    
        $('input[type=radio][name$="ListAgreements_RBL"]').change(function () {
    
            selVal = $(this).val();
    
            Filter(selVal);
    
        });
    
        dt = $("[id$='ListAgreements_GV']");
    
        selVal = $('input[type=radio][name$="ListAgreements_RBL"]:checked').val();
    
             countLabel = $("[id$='ListAgreement_LBL']");
    
    
             var table = $(dt).DataTable({
    
         scrollY: '400px',
         scrollX: true,
         scrollCollapse: true,
             autoWidth: true,
    
              paging: true,
              pagingType: 'full_numbers',
          lengthChange: true,
          lengthMenu: [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"]], 
          fixedColumns: { left: 1, right: 0 }
                
        });
    
    

    This code throws an s.match not a function error on line 5604 of the datatables.js file - function _fnStringToCss( s ). There is no error if I comment out the scrollX and scrollY lines. Think _fnStringToCss is being called directly from _fnScrollDraw( settings ) - line 5190.

    Hope this helps.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    It doesn't appear to trigger an error if I use that configuration here: https://live.datatables.net/zofobafo/1/edit .

    What version of DataTables are you using? If not the latest (2.1.7), I'd suggest updating.

    Allan

  • rsiegel64rsiegel64 Posts: 5Questions: 2Answers: 0

    Thank you for the test case, I'll take a look. Just upgraded to 2.1.7 from 1.10.x.

Sign In or Register to comment.