Mottie / tablesorter

Github fork of Christian Bach's tablesorter plugin + awesomeness ~
https://mottie.github.io/tablesorter/docs/
2.6k stars 754 forks source link

widget output and hidden rows, and childRows #923

Closed prtome closed 9 years ago

prtome commented 9 years ago

Hello, I have a strange behaviour when using the ouptut widget with child rows and (18) hidden columns 7 visible columns, children rows colspan on those 7 columns, nothing on the hidden rows I first use it without options - output is 1 row for parent, 1 row for children, visible columns only

I want to see the hidden columns to, so I add output_hiddenColumns : true, I see only the children rows, repeated 3 times

children rows are hidden , so I thought I should add output_saveRows : 'v', Same thing, I see only children rows, repeated.

Is this normal behaviour, because the widget doesnot support child rows ? thanks

(latest jquery, and download tablesorter last week - everything else is working perfectly)

Mottie commented 9 years ago

Hi @prtome!

The output widget does not differentiate between child and parent rows. So it will output rows as set by the options.

There is a output_hiddenColumns option (false by default) which will only include hidden columns if true and the column is hidden using display: none.

You can make the output widget ignore set columns using the output_ignoreColumns option.

And if you want all rows to be output, set the output_saveRows option to 'a' (or 'all').

If none of those help fix the issue, then please modify this demo and describe the expected output.

prtome commented 9 years ago

Thank you, I obviously misunderstood the docs. I wanted all columns - hidden and not, but not the child rows. If I understand well there is no way of telling it not to output some rows. I will have to rethink my data visualisation (thanks for the fiddle)

Mottie commented 9 years ago

I've thought about adding a callback per row before, but because of all the weird rowspan & colspan looping it needs to do, I left it out.

Another possibility would be to use the data-name data-attribute, set by the output_dataAttrib option, on the child row cells so they return some arbitrary string (an empty string won't work in this case because it will fall back to obtaining the cell HTML) which you could then remove in the output_callback function - I hope that make sense.

prtome commented 9 years ago

OH yes I see, I would give a name to the child row, and like this I would manage it in the callback. Need to study that. I could have the child row without a parent-rowspan which would simplify I have forked the fiddle http://jsfiddle.net/r0u8kutg/ , adding a hidden column, and a hidden row (in this case no child row). my understanding was: I add option visible, and then the hidden row will not output - but it does, and I don't understand how to have hidden and non hidden columns in the output false - only non hiddens show, true : nothing appears It's getting late here, so maybe I am just not seeing things anymore Thanks for your help

Mottie commented 9 years ago

Actually, the callback would only provide the resulting CSV or JSON, so you may not be able to differentiate the rows that way.

I just pushed an update to the master branch which now allows the data-name data-attribute to contain an empty string.

prtome commented 9 years ago

Thanks, I have to rethink my whole process I think. one think that is not clear to me (sorry english is not my first lang, so I might be missing something) output_saveRows ? I understand 'f' means I must write the filter, but the difference between visible and all ? in my fiddle test, whichever I use I get the same result. output_hiddenColumns : true desc: Include hidden columns (using display: none) in the output in the fiddle, this does not work. when selected, the output is empty. My understanding was I should see both, hidden and not hidden ? Thanks

prtome commented 9 years ago

I may have found a solution for the children rows (may, because it is half working only - and not sure it is supposed to work that way ;)

download click is

$(".download").click(function(){
        $('.tablesorter-childRow').addClass('filtered');   //<--- this works !!!!
       $('.compList').trigger('outputTable');                   // popup opens with  only parent rows :)
        $('.tablesorter-childRow').removeClass('filtered');  //doesnot remove class! even after popup is closed
    });

But I have this message in the console:

Uncaught TypeError: Cannot read property 'join' of undefined

error that is in widget.output.min.js What usually gives that error ? in the fiddle http://jsfiddle.net/r0u8kutg/ the filtered row does not show in the output, but the addClass/removeClass does not work. And no error message Any idea ? thanks (now need to find something similar to print hidden and not hidden columns together !)

Mottie commented 9 years ago

I honestly had no idea what you were expecting in the output, so I'm glad you have it at least partially figured out.

I'm not sure why the child rows are not getting the filtered class removed. It works for me in this updated demo. Maybe removing the "filtered" class in the output_callback function would work better?

I have never seen that javascript error before, can you please use the widget-output.js file (non-minified version) and report the line number of that error. Thanks.

prtome commented 9 years ago

yes, I see that it works there. Strange, I will have to look more. But the hidden columns do not show, whatever I do, even in that demo here is the line error in widget-ouput.js 177 The popup shows all the lines . Thanks for your help

Mottie commented 9 years ago

I just pushed a change to the master branch for the output widget that allows you to set the output_saveRows option to use it as a jQuery filter.

For example, setting the output_saveRows option to:

The option will still accept 'f' (filtered rows), 'v' (visible rows) and will default to all rows if the option doesn't match anything else.

prtome commented 9 years ago

Hello, Thanks, I can now export only my parents rows. It works :) but the error in widget-ouptut.js still shows. And I still have the hidden columns problem (maybe it is related to that error) in your demo (http://jsfiddle.net/r0u8kutg/1/) I changed false to true for the hidden columns, and now the export is blank - no columns at all. This is also the behaviour I have when in my code.

Mottie commented 9 years ago

Ok, the error should be fixed now! The change is in the master branch of this repository.

prtome commented 9 years ago

Yes - now I can see the hidden columns in output :) this is really great ! thanks.

(still having the error in widget-output.js : there must be something in my code triggering it, but I cannot find what - it happens in all my pages)

thanks again for this library!

Mottie commented 9 years ago

What error are you seeing in the console? Can you modify the demo to duplicate it? Is it only occurring in a specific browser?

prtome commented 9 years ago

I have it in both Chrome and Safari (I am on Mac, Yosemite , all updated).

Uncaught TypeError: Cannot read property 'join' of undefined ts.output.row2CSV @ widget-output.js:184 ts.output.process @ widget-output.js:160 (anonymous function) @ widget-output.js:37 jQuery.event.dispatch @ jquery-2.1.4.js:4435 jQuery.event.add.elemData.handle @ jquery-2.1.4.js:4121 jQuery.event.trigger @ jquery-2.1.4.js:4350 (anonymous function) @ jquery-2.1.4.js:4901 jQuery.extend.each @ jquery-2.1.4.js:374 jQuery.fn.jQuery.each @ jquery-2.1.4.js:139 jQuery.fn.extend.trigger @ jquery-2.1.4.js:4900 (anonymous function) @ companies.js:565 jQuery.event.dispatch @ jquery-2.1.4.js:4435 jQuery.event.add.elemData.handle @ jquery-2.1.4.js:4121

and this is what triggers it in my code (companies.js) -- maybe that is where it is wrong, but it works $(".download").click(function(){ // .download is the button $('.compList').trigger('outputTable'); // .compList is my table });

TheSin- commented 9 years ago

@Mottie I'll try and get setup to test and track this down shortly if I can.

Mottie commented 9 years ago

Actually, I was just looking at it.. it seems if all the header columns are hidden (demo), the error pops up.

TheSin- commented 9 years ago

ahh okay though maybe it was a mac error ;) If you are on it i'll leave ya to it ;)

Mottie commented 9 years ago

I'm not sure why all the header columns would be hidden... I could fix it so that no header is included in the CSV output, but it would totally break JSON output.

TheSin- commented 9 years ago

and hopefully that would be an option I know I personally still want headers to be in the csv. Plus I use the output widget for a few other tasks which would request the headers.

prtome commented 9 years ago

I have the error also in pages where there is no hidden column. And I have not asked ( I think) not to show the headers in output, since I see them (and I want to see them)

Mottie commented 9 years ago

Ok, try that update.

prtome commented 9 years ago

tried - no error but no ouptut :( white page instead of data

Mottie commented 9 years ago

Hmm, would you please update that demo with the HTML being used.

The code you use to trigger an output is correct, so that isn't the problem. Are you still adding a "filtered" class name to child rows?

prtome commented 9 years ago

no, i am using the new code, i don't use 'filtered' anymore. I will try to update the demo so that it reflects my code

 $('.compList').tablesorter({
      headers: {
        0: {
        // disable it by setting the property sorter to false
        sorter: false
            }
          },
      widgets: [ "output"],
        widgetOptions : {
            output_separator     : ';',         // ',' 'json', 'array' or separator (e.g. ',')
            output_ignoreColumns : [0,7],          // columns to ignore [0, 1,... ] (zero-based index)
            output_hiddenColumns : true,
            output_saveRows      : 'f' ,
            filter_filteredRow : 'pasprint'
        }
      });
prtome commented 9 years ago

http://jsfiddle.net/breLqs3z/

in here like I use it, and result is a blank page

Mottie commented 9 years ago

That's because that demo is using the output widget from the gh-pages branch... if you point to the output widget in the master branch (https://rawgit.com/Mottie/tablesorter/master/js/widgets/widget-output.js), it works fine: http://jsfiddle.net/Mottie/breLqs3z/1/

prtome commented 9 years ago

sorry, i am not good yet with fiddle. I forked that last demo, and added the filter for the childrenrows, and it works, so now to my code. I have downloaded the code from your link, yes I get the output, but I still get the error on same line.

I re downloaded the widget-output.min.js from https://github.com/Mottie/tablesorter/tree/master/dist/js/widgets
(since I had downloaded everything from there) and now I get the error: Uncaught SyntaxError: Unexpected token < widget-output.min.js:4

maybe I should clean the directories, redownload all and check everything again Thanks

prtome commented 9 years ago

I can't get it working anymore. Downloaded the last version from github - I get a white page. Now even when I download your link - same thing. I got back to the "working with console error" version . I will try again after a few hours, I must be reproducing some errors in download, better give it a rest. Thanks

Mottie commented 9 years ago

Try downloading the files from the repository zip file: https://github.com/Mottie/tablesorter/archive/master.zip

prtome commented 9 years ago

No, I cannot get it working. I downloaded from your link, and get a white page, whatever I do I give up for now, maybe in a few days I sort this out. I am back with the version I could get working, even if it has an error thanks

prtome commented 9 years ago

Found out - there was an error in my code -embarrassingly simple - the download button appeared in 2 tables, each on its own tab. One of the tables was empty - and that is why the ouptut-widget was giving an error - and I think that is why once the error disapeared, I could see nothing anymore : in fact it was showing (correctly) the second table. Thanks a lot !