Mixed up columns when changing the visibility of columns and reordering the columns using ColReorder

Mixed up columns when changing the visibility of columns and reordering the columns using ColReorder

systembotsystembot Posts: 4Questions: 0Answers: 0
edited January 2012 in General
Hi all,

I am right now facing the difficulty that I made the column visibility customisable (not using ColVis plugin but own implementation) via a dialog and want to make the column order customisable (using ColReorder plugin) as well. Unfortunately, I can only provide integer arguments to the function fnSetColumnVis(INT, bool, bool). If I reorder the columns the wrong indices will be used to set the visibility of the columns. It would be easiest to identify the columns if the function fnSetColumnVis would accept a string ( fnSetColumnVis(STRING, bool, bool) ). If the function fnSetColumnVis(INT, bool, bool) only accepts integer values, I need to find out about the new position (integer value), which means the new order of the columns, so that I can switch the visibility of the right columns. Does this relate to the column property 'mDataProp'? I suppose I need to extract the position of the columns from the GET-parameters mDataProp_0='', mDataProp_1 = ', ... . Can someone give me some hints how to do this? Many thanks in advance.

Best regards,
systembot

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    My example server-side processing code shows how it might be done: https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/objects.php

    However you are quite right - it would be great if fnSetColumnVis and other functions took a string identifier for columns. They will in future as I plan to introduce this in 1.10 or 1.11 depending on how things go! Until then you would could give an sName to each column and then look up the index of the column name in the fnSettings().aoColumns array.

    Allan
  • systembotsystembot Posts: 4Questions: 0Answers: 0
    Thanks for the quick response, Allan. :-) I got an inspiration that solves the problem and it seems that sometimes live can be very easy. :-)

    I construct an associative array which the keys being the names of the columns I assigned with mDataProp and sName and the values being the positions of the columns after reordering them. After that I use the array to tell fnSetColumnVis at which positions the columns can be find.

    [code]
    ...
    var columnNameArr = oTable.fnSettings().aoColumns;
    var order = new Array();
    for (var i = 0; i < columnNameArr.length; i++) {
    order[columnNameArr[i].mDataProp] = i;
    }

    oTable.fnSetColumnVis(order[''], $('#').is(':checked'), false);
    ...
    [/code]

    Best regards,
    systembot
This discussion has been closed.