Splitting data across multiple tables on a page

Splitting data across multiple tables on a page

ThomDThomD Posts: 334Questions: 11Answers: 43

I have a page with 8 mini tables (just two columns), pulling data from a single JSON data source. The Data set is divided into one of 4 categories. Within each category, I have a top 10 and Bottom 10 display. For example, if I had a category of color and a value of price, I'd have a table for Top $ Red, Top $ Blue, Top $ Green, Top $ Yellow and Bottom $ Red, Bottom $ Blue, Bottom $ Green, Bottom $ Yellow.

This all works, but I've done it sort of brute force. I load data set fully into each table, sort the table asc or desc and apply a filter for category. By removing the paging elements and the ability to sorting options, I get the top and bottom 10 in each category.

This seems a bit inefficient. I'm left with many extra rows in tables that I will never display (all the rows are in all the tables).

I could run a rows().remove() by category after I populate each table, but again, that's not elegant.

Is there a way in the datatables init to exclude (or immediately drop) a row? I could probably split the JSON at the source, but I'm hoping to avoid that.

This question has accepted answers - jump to:

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015 Answer ✓

    Have you thought about maybe using a closure as the value of data? And parsing or restricting the amount of results it returns? Thats the way I would do it

    EDIT: Oh... After reading the data page, I see it only takes an array as the value. I know you can use a closure for the value of ajax, im sure you could use that though?..

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Well, once I fired it up, the performance isn't bad, so I may leave it alone. Tinkering with the ajax option is probably a good approach, but then I'd have to figure out how to inspect deep inside the json object to filter for the records I need. it's only 300 smll records, so I can live with it as is.

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    If I were you, id use the ajax param with a closure, and use the filter method within lodash, (Or even UnderscoreJS works, I just think LoDash is better :) )

    That seems to be the most efficient way, I definitely wouldnt delete the rows or just hide the pagination, that just seems.. hanky? If thats the right term, lol

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    The word you are looking for is janky. But, as a wise man once said, "If it is stupid, but it works, it ain't stupid."

    On to the next project....

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    Answer ✓

    As another smart man once said, "If its worth doing, its worth doing right" ;-)

This discussion has been closed.