简体   繁体   中英

jQuery DataTables 1.10 server side processing columns

I am having trouble getting columns definitions to stay when I am doing server side processing. I have looked at the documentation on the http://datatables.net/ site and don't see anything obvious that I can try. I have tried using the AJAX option with callback but that wasn't formatting it either. Here is what my javascript currently looks like.

$(this).dataTable({ sPaginationType: "full_numbers", bJQueryUI: true, processing: true, bServerSide: true, sAjaxSource: $(this).data('source'), columns: [ { width: "10%" }, { width: "20%" }, { width: "70%" } ] });

If I remove the sAjaxSource and bServerSide nodes it formats the columns correctly. Giving the right column the most width. If I put those lines back in it doesn't do any formatting.

Any help would be great.

I finally figured out what was happening here. If you try to pass the dataTable a percentage like I did above it appears to not be working. This is because it concerts them to pixels before applying them. So in my case it didn't appear to be working because it would auto size them after it ran out of pixels. The resolution for this is to pass in a number and only pass it in for the columns you want to size. Something like this works as expected.

$(this).dataTable({ sPaginationType: "full_numbers", bJQueryUI: true, processing: true, bServerSide: true, sAjaxSource: $(this).data('source'), columns: [ null, null, { width: "150" } ] });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM