De-duplicating table redraws

De-duplicating table redraws

JCiiJCii Posts: 7Questions: 0Answers: 0
edited September 2011 in General
Greetings all,

I have a page that uses datatables to display two sets of information. I have a series of buttons that allow the user to filter data.

The buttons change some state variables and call an Update routine. Based on the state, the Update routine may hide or show a column [ fnSetColumnVis ], clear the search filter [ fnFilter("") ] or just call fnDraw [ fnDraw() ]

The problem I'm trying to solve is that if the column show/hide state changes, the fnSetColumnVis makes an Ajax call to the server; when I get to the fnDraw/fnFilter code, it draws again. I'd like to remove the extra call to the server for efficiency purposes.

Is there a way to tell fnSetColumnVis not to re-draw, or combine all the changes to Datatables into one call?

Thanks

-Jimmy

Replies

  • JCiiJCii Posts: 7Questions: 0Answers: 0
    This will probably help in explaining what I'm working with:
    [code]
    $("#updateBtn").click(function (e) {
    e.preventDefault();
    if ($('#assignedWorker_visible').val() == 'true') {
    $("#availAssignTable").dataTable().fnSetColumnVis( 0, true );
    } else {
    $("#availAssignTable").dataTable().fnSetColumnVis( 0, false );
    }
    if ($('#signin_visible').val() == 'true') {
    $("#signinTab").show();
    } else {
    $("#signinTab").hide();
    }
    //alert($("#signinTable").dataTable().fnFilter());
    if ($('#signinTable_filter').val() == null) {
    $("#signinTable").dataTable().fnDraw();
    } else {
    $("#signinTable").dataTable().fnFilter("");
    }
    if ($('#availAssignTable_filter').val() == null) {
    $("#availAssignTable").dataTable().fnDraw();
    } else {
    $("#availAssignTable").dataTable().fnFilter("");
    }

    });
    [/code]
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    fnSetColumnVis has an option that you can pass to it to tell it to not redraw the table:

    http://datatables.net/api#fnSetColumnVis (3rd parameter)

    fnFilter ( http://datatables.net/api#fnFilter ) however does not have such an option. It would be possible to construct a plug-in API method which sets the filtering and then doesn't act upon that filter until a full draw is done next, but there currently isn't a built-in way of doing that.

    Regards,
    Allan
  • JCiiJCii Posts: 7Questions: 0Answers: 0
    Duh. Thanks. I went looking for something like that, but missed it.

    -Jimmy
This discussion has been closed.