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

list of columns to exclude #2

Open
derekeder opened this issue Jun 13, 2015 · 4 comments
Open

list of columns to exclude #2

derekeder opened this issue Jun 13, 2015 · 4 comments

Comments

@derekeder
Copy link
Owner

It's possible someone won't want to display every column in their CSV. Could handle this by passing in a list of columns to exclude.

@mm108
Copy link

mm108 commented Aug 25, 2015

Yup, I already needed that so I implemented it my way. Just in case anyone needs this for now
Firstly I declared an array with the column (index) that I need.

var displayColumns = [0, 3, 4, 5];
var colIndex =0;

// A function to check if the value exists in the array
var indexOf = function(needle) {
    if(typeof Array.prototype.indexOf === 'function') {
        indexOf = Array.prototype.indexOf;
    } else {
        indexOf = function(needle) {
            var i = -1, index = -1;
            for(i = 0; i < this.length; i++) {
                if(this[i] === needle) {
                    index = i;
                    break;
                }
            }
            return index;
        };
    }
    return indexOf.call(this, needle);
};
// And before I add a column I do a lookup. The above function returns >=0 if the col index is
// found in the array
                            for (head_id = 0; head_id < csv_data[0].length; head_id++) {
                                // table_head += "<th>" + csv_data[0][head_id] + "</th>";
                                colIndex = indexOf.call(displayColumns, head_id);
                                if (colIndex >= 0) {
                                    table_head += "<th>" + csv_data[0][head_id] + "</th>";
                                }
                            }
// You will also need to do the same thing when adding the row data. The above code is only when
// adding heading row. You just need to do the same thing in the subsequent for loop

@stephenhouser
Copy link

stephenhouser commented Jan 30, 2017

Isn't this already handled with

datatables_options: {
      "columnDefs": [
            {
              "targets": [6, 7, 8, 9],
              "visible": false
            },
}

@jimmyhartington
Copy link

I can not get the datatables_options to work to hide some columns.

Do you have an example of it implemented in a index.html ?

@rvelseg
Copy link

rvelseg commented Jul 20, 2018

here is a longer piece of code

<script>
  CsvToHtmlTable.init({
    csv_path: 'data/Health Clinics in Chicago.csv', 
    element: 'table-container', 
    allow_download: true,
    csv_options: {separator: ',', delimiter: '"'},
    datatables_options: {"paging": false,
                             "columnDefs": [{"targets": [2, 3], "visible": false }]},
  });
</script>

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

No branches or pull requests

5 participants