alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 363 forks source link

Issue trying to process actions on dynatable page clicks always #250

Open hammerva opened 8 years ago

hammerva commented 8 years ago

Good afternoon. I created an issue a couple weeks but after updating significantly so thought I would create a new one and close the other one. I am trying to do some action on a few fields in my dynatable 'checkedTable'. Here is the code that I currently have:

       $(document).ready(function () 
     {

       $("table#checkedTable").dynatable().on("dynatable:afterProcess", disableBehavior());  

       function disableBehavior() 
        {

          $(document).on('click', '.dynatable-page-link', function() 
          {

            var statusCheck = '<%= session.getAttribute("statusEFTC") %>';
            var passedError = "N"  ;

           alert ("Inside the click function in page-links the statusCheck is " + statusCheck) ;

           if (statusCheck !== 'VP')
           {
               $('table#checkedTable input[type=checkbox]').attr('disabled','true');
               $('table#checkedTable input[type=text]').attr('disabled','true');
               $('table#checkedTable select[id^=Modify]').attr('disabled','true');
          }  
          else
          {
             $('table#checkedTable input[type=checkbox]').removeAttr("disabled");
           }
    }              

I can get this processing to work on the load of the page. I can get this processing to work when I click on any of the page clicks (page numbers, Previous, Next, etc) the first time. But any other time after that it won't work. I am accessing the function based on alerts every time but when I click on the page click the data that it is checking is different. When I do it the first time, it is processing data on the page that I am going to. Every other time it is processing data from the page before. I have worked with people in my account and we can't seem to fix this issue. can you please take a look and see if this is an issue with my coding or in dynatable processing itself. If you have an example where an action occurs (alert box for example) EVERY single time the page links are clicked that it works could you please provide that.

Thanks for any help.

dnsBlah commented 8 years ago

Hi Hammerva,

I'd like to thank you for your disableBehaviour approach. For me with a few adjustments it works great, for re-applying some tablerow styles using jquery. Please see this approach:

    $("table#changeTableClosed").dynatable().on("dynatable:afterProcess", dyntablePagination());  
    function dyntablePagination()  {
         $(document).on('click', '.dynatable-page-link', function() {
             setTimeout(function(){
                 processPaginition();
             },0);
         });
     }

    function processPaginition() {
        dynatableClosed.process();

        $('#changeTableClosed tr td').each(function(){
            if($(this).html().indexOf('P1') != -1)
                $(this).parent().addClass('redHighlight');
            else if($(this).html().indexOf('P2') != -1)
                $(this).parent().addClass('amberHighlight');
        });
    }
//Don't forgot records per page change.
$(".dynatable-per-page-select").on('change', function(event) {
        processPaginition();
});

You have to use the timeout, else it's not working at all. Use this approach to alter the values you need.

hammerva commented 8 years ago

Pardon my french but holy shit that actually worked on my processing. At least it seems to be so far. Can you please explain to me why the 'setTimeout' was needed on this? Is this tied specifically to dynatables? Also what is your dynatableClosed function call? Is that something specific to your project that isn't really tied to the process

Thanks plenty for help on this.

dnsBlah commented 8 years ago

Hi @hammerva,

Ehm sorry I should've explained the 'id' #dynatableClosed This is just the attribute 'id' I gave to my table object. It's a table containing my tickets system, and this was a sample of my 'closedTickets' overview ;-) But you need to provide your id of the table, if you are using it. (I have 5 dyntable instances on 1 page :) )

The reason for setTimeout, is ... I don't know :D but if I don't use the Timeout it's not working. Currently still figuring out how to restore my javascript functions after initiating the dynatable.

By the way, found some more :)

//Records per Page change
    $(".dynatable-per-page-select").on('change', function(event) {
        processPaginition();
    });
    //Ordering links
    $(".dynatable-sort-header").on('click', function(event) {
        processPaginition();
    });
    //Search fields change see where my changeTableOpen is, there should be the ID of your table
    $("#dynatable-query-search-changeTableOpen").on('change', function(event) {
        processPaginition();
    });