How to reload data upon sorting
How to reload data upon sorting
Hello, I am working on an application that compares prices of products between different sellers. One feature I have added is buttons to hide certain columns using colvis (toggled). However, the data in one of the other columns that always shows is dependent upon the other columns -- the discount is computed based on the difference between our price (the CDO column) and the lowest price of the other five sellers (Maxiconsumo, Makro, Vital, Yaguar, and Diarco). So, if I hide a seller column that had the lowest price for a given product, I will need to recalculate the discount based on the next lowest price seller. Similarly, if I add a column in, I will need to check to see if its price beats the current lowest seller's price, so I would recalculate the discount. I also color the cell with the lowest seller price green in a row callback function, so that will need to be re-executed again as column visibility changes.
Some ideas I had to approach this issue were to simply reload the table every time a column visibility button is clicked (using ajax.reload()), but I am not sure how to implement it with specificity to the columns that are present. My data contains an array of objects containing the sellers' prices and discounts with respect to the CDO price, and I have sorted the array in ascending order of prices in my backend. So, if Maxiconsumo has the lowest price, followed by Diarco, and the other three sellers do not have the item, the array will be of length 2 and contain the Maxiconsumo object at index 0 and the Diarco object at index 1. Is the sorted array a workable implementation, or is it better to keep the array in order of how the columns are presented and iterate through each time to find the lowest price? Let me know what you think, and please let me know if you need more information to help debug. I am not sure if it is helpful to give a test case because my issue pertains to how my data is loaded in; let me know if it would be useful, and I will try my best.
Replies
Here is the index.html file.
Hi @janetcl ,
I can't really comment on most of that, I'm afraid, it's more of a coding issue rather than a DataTables specific issue which is the intent of this forum. One consideration though, would be your line here:
ajax.reload()
will always reload the entire data, it isn't selective.Cheers,
Colin