Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCROLL X Breaks the resizing of the columns #6

Open
andreadrupal opened this issue May 18, 2018 · 12 comments
Open

SCROLL X Breaks the resizing of the columns #6

andreadrupal opened this issue May 18, 2018 · 12 comments
Labels

Comments

@andreadrupal
Copy link

Hi,
i have the need to use very large tables, and i need to enable the scrollX=true parameter in datatable.
Unfortunately, the scrollX breaks the resize of the columns (the table body start the new width from 0 px).
resize_bug

@jeffreydwalter
Copy link
Owner

I'll have to compare the behavior in the ColReorder plugin. I think you need to set a pixel width for the table, instead of 100%.

@jeffreydwalter
Copy link
Owner

Looking at this example, it looks like you need to set the width of the dataTables_wrapper to a fixed width and the table width to 100%, like you have. Have you tried that?

div.dataTables_wrapper {
        width: 800px;
        margin: 0 auto;
    }

@andreadrupal
Copy link
Author

I would like not to give a fixed with, because i am in a liquid page context. The original ColReorder worked fine with the scrollX option :(

@jeffreydwalter
Copy link
Owner

No worries. You are right, this is broken. I am working on a fix and should have it later today.

@jeffreydwalter
Copy link
Owner

@andreadrupal I just committed a fix to make this plugin work better with scrollX, scrollY, and non-scroller tables. Please give it a try and let me know if you find any issues.

@jeffreydwalter
Copy link
Owner

jeffreydwalter commented Jul 3, 2018 via email

@ShaheedHaque
Copy link

ShaheedHaque commented Jun 18, 2019

I can confirm that master (d4d9d5b) with dataTables and scrollX works as expected.

@rohithtsgowda
Copy link

@jeffreydwalter @ShaheedHaque
I have used the above updated ColReorderWithResize js file and trying to initialize the JS plugin with 'dom': 'Rlfrtip'. But Resize of the column is not happening but reorder is working. Please let me know if am missing anything here. My requirement is to have DataTable column resize with ScrollX or ScrollY.

$('#table').DataTable({
'dom': 'Rlfrtip',
searching: false,
scrollCollapse: true,
autoWidth: true,
serverSide: true,
lengthChange: false,
scrollY: 160,
deferRender: true,
iDisplayLength: 300,
paging: true,
initComplete: function () {

@ShaheedHaque
Copy link

I use these args by default:

{
    // Add a hook to the DOM to allow additional controls to be added.
    dom: `R<'row'<'col-sm-12 col-md'l><'${selector}_controls.col-sm-12
    col-md-auto'><'col-sm-12 col-md'f>>
    <'row'<'col-sm-12'tr>>
    <'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>`,
    'colReorder': {
        'allowReorder': false,
    },
    pageLength: 25,
    scrollX: true,
    // Disable the default initial [0, 'asc'] sort.
    order: [],
    stateSave: true,
    stateDuration: -1,
};

but I also set the width:

    this.table = $(selector).dataTable();
    this.table.css('width', '100%');
    this.table.api().draw();

I hope that helps.

@luisorduz
Copy link

var contadortableAfiliado = 0;
$('#tableAfiliado_wrapper .dataTables_scrollBody').on('scroll', function(e) {
contadortableAfiliado++;
if(contadortableAfiliado === 30 ){
tableAfiliado
.order( [ 10, 'asc' ] )
.draw();
contadortableAfiliado = 0;
}

});

@arindamINT
Copy link

Hello @jeffreydwalter Sir,

I am using the latest version of this js file. Recently I noticed that when the table is in scrollX: true, mode or it has a horizontal scroll feature, then when I am resing the column the header of the column are shifting to left 0 positions and after releasing the mouse it is taking again the right position with proper new width. It is only happening when the horizontal scroll is not in 0 positions.

I have also attached the video for a better understanding of the issue.
VIDEO LINK: https://drive.google.com/file/d/1HysIw2kf8uaT524yelDIKxVSeSBf9hWp/view?usp=drivesdk

To resolve this issue I have added these two lines inside the resizing function. Check the attached screenshot. But unfortunately this process has not resolved the issue properly.

    this.dtOptions = {
      paging: false,
      info: false,
      searching: false,
      ordering: false,
      scrollY: 'calc(100vh - 390px)',
      scrollX: true,
      dom: 'Rlfrtip',
      colReorder: {fixedColumnsLeft: 1, fixedColumnsRight: 1 },
      autoWidth: true,
    };
/* When scrolling we need to recalculate the column sizes to allow for the shift */
this.s.dt.oInstance.fnAdjustColumnSizing( false );
/* Save the state */
this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );

modification

@arindamINT
Copy link

@jeffreydwalter
Hello sir, I have noticed that if I used searching: false, then only this issue is happening, otherwise not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants