reportico-web / reportico

Reportico Open Source PHP report Designer
MIT License
166 stars 70 forks source link

How to add additional option in datatable #18

Open Er-Kalpesh opened 7 years ago

Er-Kalpesh commented 7 years ago

Existing and working code :

/*
 ** Reportico Javascript functions
 */
function setupDynamicGrids()
{
    if (typeof reportico_dynamic_grids === 'undefined') {
        return;
    }
    if (  reportico_jquery.type(reportico_dynamic_grids) != 'undefined' )
        if ( reportico_dynamic_grids )
        {
            reportico_jquery(".swRepPage").each(function(){
                reportico_jquery(this).dataTable(
                    {
                        "retrieve" : true,
                        "searching" : reportico_dynamic_grids_searchable,
                        "ordering" : reportico_dynamic_grids_sortable,
                        "paging" : reportico_dynamic_grids_paging,
                        "iDisplayLength": reportico_dynamic_grids_page_size
                    }
                );
            });
        }
}

but if i try to add extra option in datatable like following code then it throws error :

/*
 ** Reportico Javascript functions
 */
function setupDynamicGrids()
{
    if (typeof reportico_dynamic_grids === 'undefined') {
        return;
    }
    if (  reportico_jquery.type(reportico_dynamic_grids) != 'undefined' )
        if ( reportico_dynamic_grids )
        {
            reportico_jquery(".swRepPage").each(function(){
                reportico_jquery(this).dataTable(
                    {
                        "scrollCollapse": true,
                        "autoWidth": false,
                        "scrollX": true,
                        "retrieve" : true,
                        "searching" : reportico_dynamic_grids_searchable,
                        "ordering" : reportico_dynamic_grids_sortable,
                        "paging" : reportico_dynamic_grids_paging,
                        "iDisplayLength": reportico_dynamic_grids_page_size
                    }
                );
            });
        }
}

So please guide me that how can we pass extra options to reportico datatable ?

reportico-web commented 7 years ago

Hi there planning to try this iver the weekend what error do you get?

Peter

Er-Kalpesh commented 7 years ago

TypeError: s.match is not a function[Learn More] jquery.dataTables.js:4214:10

Er-Kalpesh commented 7 years ago

Hello @reportico-web Is there any updates on this ? Are you able to reproduce the error at your end ?

reportico-web commented 7 years ago

Ok I got your mail as you need it i will take a look when I get back from holiday later this week ...probably I will try to replace with latest version of data tables

Er-Kalpesh commented 7 years ago

Many Many thanks Sir.

reportico-web commented 7 years ago

Hi there... ok I have been looking at this.... I have some points..

firstly, there seems to be something here .. this seems to indicate workaround setting scrollX and scrollY to "100%"

It looks like upgrading reportico with later datatables should fix it .. let meknow if setting scrollX to "100%" will work

Peter

Er-Kalpesh commented 7 years ago

Hello Peter,

I tried that solution but still not working : TypeError: s.match is not a function[Learn More]

function setupDynamicGrids()
{
    if (typeof reportico_dynamic_grids === 'undefined') {
        return;
    }
    if (  reportico_jquery.type(reportico_dynamic_grids) != 'undefined' )
        if ( reportico_dynamic_grids )
        {
            reportico_jquery(".swRepPage").each(function(){
                reportico_jquery(this).dataTable(
                    {
                        "scrollX": "100%",
                        "retrieve" : true,
                        "searching" : reportico_dynamic_grids_searchable,
                        "ordering" : reportico_dynamic_grids_sortable,
                        "paging" : reportico_dynamic_grids_paging,
                        "iDisplayLength": reportico_dynamic_grids_page_size
                    }
                );
            });
        }
}
reportico-web commented 7 years ago

Hi, firstly did you refresh your cache or CTRL+F5 before reloading ?

secondly what happens if you try "scrollX": 1 ?

the function that is causing the error in dataTable.jquery.js i think is this ( around line 4214 )

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;
}

I think that that s.match is trying to work string matching on something that isnt a string.

the problem i have here is that reportico loads in a minified file jquery.datatables.min.js .. the error you have shows file jquery.dataTables.js so the question i have is.. is there another datatables being loaded somewhere else in the web page? Are you able to go into debug mode in your browser, and find the path of this path and put a break point into this file and see what the value of "s" is? if not dont worry

I see on your stack overflow post you re using the Yii2 module, how are you runnning the report .. eg as an embedded code ( if so can you share the code ), as standalone reportico call?

I sure we can solve this .. so please get back to e with answers to above and we can go to next step :-)