How to hide row automatically based on entry in column, with option to show all and hide all
How to hide row automatically based on entry in column, with option to show all and hide all
FurnishedHomes
Posts: 13Questions: 0Answers: 0
Hi,
I would like to create a new column in my datatable called delivery status. It will say either pending or complete. When the entry says complete it will automatically hide that row. However if the user clicks a show all button it will re-appear and they can change the status to pending, then click a button to hide all 'completed' again. Is this possible? I would love to post a link but unfortunately the site is not live but on a local server and contains private information. Any help would be much appreciated
I would like to create a new column in my datatable called delivery status. It will say either pending or complete. When the entry says complete it will automatically hide that row. However if the user clicks a show all button it will re-appear and they can change the status to pending, then click a button to hide all 'completed' again. Is this possible? I would love to post a link but unfortunately the site is not live but on a local server and contains private information. Any help would be much appreciated
This discussion has been closed.
Replies
1. Add the new column. you can do that by simply adding it to the HTML and Javascript used for the table (the PHP as well if you are using the Editor PHP libraries). Sounds like either would be a good option for either a radio input or select input.
2. Showing and hiding the rows: I'd do that by applying a filter to the table. You could either use the global filter, but more likely (since you will probably want to keep the global filter for the user's use) you'll want to use a custom filter: http://datatables.net/development/filtering#row_filters . Using that method you could simply set a variable to indicate if the rows should be filtered out or not and the filtering plug-in would act on that. Then simply redraw the table whenever you want to update the display ( fnDraw ).
Allan
ok, well I've added my new column but I had to edit 216 entries to reflect the new column! So been a bit delayed. I have also been looking at this thread
http://datatables.net/forums/discussion/7280/programmatically-hide-rows/p1
would something like this work? (where my column is called status and the entries are pending or completed) If so how would I implement it on my html page with 2 buttons to show all and to hide all again. (or would I not need a hide all again if I were to refresh the page?
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex )
{
var row = oSettings.aoData[iDataIndex].nTr
, show = $(".toggle-row-display .selected").data("show")
, status = +$(row).data("Status");
if(show === "all")
{
return true;
}
else if(show === "Pending")
{
return (status === 1);
}
else if(show === "Completed")
{
return (status === 0);
}
else
{
return true;
}
}
);
$(".toggle-row-display a").live("click", function()
{
$(".toggle-row-display a").removeClass("selected");
$(this).addClass("selected");
$("#deliveriesdb").dataTable().fnDraw();
return false;
});
I've tried a number of things to try and get a button talking to that js file including:
Hide / Show Completed Jobs
Some help with this would be great, assuming the code above is correct and should work Im just a button away from a finished project!
I've used a global variable `_show` as well to try and keep the filter nice and fast, but you might want to tidy that up into a private parameter possibly.
Regards,
Allan
Allan
I know I'm digging this up from the grave. But I'd love to see that example again. Trying to work to a deadline but can't seem to get this functionality sorted.
Basically what I had done was to simply use a custom filter ( http://datatables.net/development/filtering - "Custom row filter" section) which would read a variable that was set by a click on a console. Clicking on it, would set the variable and cause a redraw. The redraw causes the filter to occur and thus the table is correctly displayed.
I'm a bit rushed at the moment so I can recreate it as was just now, but if you run into problems let me know and I'll try to do so next week.
Allan