About Fixed Column
About Fixed Column
pm5249
Posts: 28Questions: 8Answers: 0
Hi Alen,
I want to make my dataTable's first 2 columns fixed and I am using the way you showed in the example but the issue is I am using older version of jquery. Like you have mentioned jquery 1.12.4 but I am using 1.10.4. and I am using that version throughout my application. If fixed column structure needs jquery version 1.12.4 then it seems I would not be able to use this functionality.
Is there any solution on this? Please suggest me.
Thanks.
PM
This discussion has been closed.
Answers
jQuery 1.10.x should work fine. In fact anything later than 1.7 should work okay.
Allan
Thanks Allan,
But you have mentioned that it needs DataTable js version 10.12.16 and I am using 10.12.10 for 2nd version it is not working.
PM
There is no 10.12.16 version of either jQuery of DataTables.
The current release of DataTables (1.10.16) will work with any version of jQuery from v1.7 or newer. This information is available on the compatibility page.
Allan
Its ok Allan. There might be typo mistake from me, but it still not working.
this is what my dataTable code is.
myDatatableProduct=$('#productConfigurationList').DataTable( {
"sDom": '<lf<"#gobutton"><"#actions"><t>ip<"clear"<".productConfigurationactions">>>',
orderCellsTop: false,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
scrollY:"300px",
scrollX: false,
scrollCollapse: true,
paging: false,
fixedColumns: {
leftColumns: 2
},
"columnDefs": [
{ "width": "20%", "targets": 0 }
],
//alert(d);
if (!select.find('option[value="' + d + '"]').length) {
select.append( '<option value="'+d+'">'+d+'</option>' );
}
if(index == 16)
{
if (!select.find('option[value="All"]').length) {
select.append( '<option value="All">All</option>' );
}
}
});
Its yet now working.
it shows horizontal scroll bar for thead and vertical and horizontal scroll bar for tbody but columns are not fixed.
Happy to take a look at a test case showing the issue.
Allan
You want code for it? or you want to see what causes this issue?
hey allen,
See this is my HTML Code
<
table id="pricingTable" class=" table table-striped table-hover display" cellspacing="0" width="100%">
<thead>
<tr id="filterrow">
<th></th>
<th></th>
<th data-hide="true" class="smallWidth"></th>
<th class="smallWidth"></th>
<th class="smallWidth"></th>
<th></th>
<th class="smallWidth"></th>
<th class="smallWidth"></th>
<th></th>
<th class="smallWidth"></th>
<th class="smallWidth"></th>
<th></th>
<th class="smallWidth"></th>
<th class="smallWidth"></th>
<th></th>
<th class="smallWidth"></th>
<th class="smallWidth"></th>
<th></th>
</tr>
<tr>
<th>Description</th>
<th>Type</th>
<th data-hide="true" class="smallWidth">Algorithm</th>
<th class="smallWidth">GRP</th>
<th class="smallWidth">US</th>
<th>Canada CAD</th>
<th class="smallWidth">LA</th>
<th class="smallWidth">US</th>
<th>Canada CAD</th>
<th class="smallWidth">LA</th>
<th class="smallWidth">US</th>
<th>CAD</th>
<th class="smallWidth">LA</th>
<th class="smallWidth">US</th>
<th>CAD</th>
<th class="smallWidth">LA</th>
<th class="smallWidth">US</th>
<th>Canada CAD</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sample1</td>
<td>Sample2</td>
<td data-hide="true">sample3</td>
<td class="pop popException" >4000</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
<td>1680</td>
</tr>
</tbody>
</html>
This is the js code
*** Pricing Table Creation ***/
var priceTable = $("#pricingTable").DataTable({
"sDom": '<lf<"#priceGobutton.actions"><"#priceActions.actions"><t>ip<"clear"<"#savebutton">>>',
orderCellsTop: false,
fixedHeader: true,
fixedColumns: {
leftColumns: 2
},
scrollX: true,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
initComplete: function () {
$("div.toolbar11").html('<b>Custom tool bar! Text/images etc.</b>');
$select = $('<select/>').appendTo('#priceActions');
$select.attr('id', 'selectactions');
$select.addClass("myselectstyleforactions combobox");
$('<option/>').val('').text('Actions').appendTo($select);
$('<option/>').val('showhidecols').text('Show/Hide Columns').appendTo($select);
//$("#priceGobutton").html("<button class='form-control btn populate_submit_save_btn' onclick='performAction()'>Go</button>");
var goButton = $("<button>").addClass("form-control btn populate_submit_save_btn").attr("type", "button").html("Go");
$("#priceGobutton").html(goButton);
priceTable.on( 'draw', function () {
//Hide the columns which should not shown bydefault.
var hiddenColumns = $("#pricingTable thead th[data-hide=true],#pricingTable tbody td[data-hide=true]");
$(hiddenColumns).addClass("hideClass");
});
These are the js files I have called on html page including jquery
This is what I am getting error.
One more thing I am facing one issue because of one function if I removed that function then I am getting error :
jquery.dataTables.min.js:59 Uncaught TypeError: Cannot read property 'style' of undefined
Please see this tech note for information on how to provide a test case.
Allan
Hey Allen
Thanks I just checked with jsfiddle over there it is working well but when I use it at my end it is not working.
Please provide a link to your test case.
hi Allen,
It worked for me but only one issue I am getting error saying Style of undefined why is that?
PM
Please provide a link to your test case.
I am not able to provide the test case as the code is confidential. just let me know my table structure it disturbed when i use Datatable in bootstrap tabs. tables gets disturbed in the tab which is not active.
Can I make column fixed on button click?
One more issue Allen,
When I use version 1.10.16 draw callback doesn't work.
It appears to work without issue here: http://live.datatables.net/mahukuya/1/edit
We'd need a link to a page showing the issue. As noted in the tech note I linked to before you can use services such as JSBin or JSFiddle to create a test case without the confidential information.
I'm afraid I can't offer any help without a test case.
Allan
Its Ok Allen,
You have already helped me alot but I am not understanding why draw is not working rather it is not getting called.
Allen,
does it need higher version of jquery like 1.11.3 which has been mentioned in link? I am using 1.10.2.
Allen,
I cant show you the test case but here I have made one sample project over there its not working at all. You can see the screenshot
.
https://jsfiddle.net/PM5249/fttne1eh/
See this sample code link I am sharing.
That is wrong. As the documentation notes (and Kevin's example from the other thread on the same topic) it should be
drawCallback
. Note the capitalisation. Javascript is case sensitive.Allan