SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: Sorttable

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorttable

    Hello.

    I am using sorrtable javascript code for sort table data.

    But while using Ajax to fetch mysql data , this is not working.
    I found solution on the website , but U am really beginner in javascript code , so I dont know hot to implement it.


    You have to manually call the function sorttable.makeSortable() passing it the table you just got back from AJAX. The simplest way to do this is to give your table an ID and then use:



    Code JavaScript:
    sorttable.makeSortable(document.getElementById('the_table_id'));

    Could anyone help me out?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    We cannot help you with this until we know about the ajax calls that you are making, which update the table.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide a link to the site, or some sample code?

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SlickAU View Post
    Can you provide a link to the site, or some sample code?
    word sorttable was linked above , but if you dont see here it is :

    http://www.kryogenix.org/code/browser/sorttable/

    This is not working with onload events. I mean :

    Select form with some options , after selecting any of option data is fetched , but sorttable not working.

    Otherwise without selecting form works well. So probably function have to be called again after fetching data with ajax.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nydiann View Post
    word sorttable was linked above
    Ahh, there's some confusion here.

    We want to be able to have a look at your ajax code that's having the trouble. As there are many different ways to do ajax code, there are many possible solutions. Once we know what you're working with, we can suggest a solution that will help you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here I uploaded some examples :


    test/test123

    With onload content using ajax
    http://tsp.nstrefa.pl/sorttable/


    And normal fetching data.
    http://tsp.nstrefa.pl/sorttable/getuser.php

    Ajax code is so simple , getting by element id

    Code JavaScript:
    <script type="text/javascript">
    function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
     
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","js.php?q="+str,true);
    xmlhttp.send();
     
    }
     
    </script>


    and html form :

    Code HTML4Strict:
    <form>
    <select name="users" onchange="showUser(this.value)">
    <option value="">Select a person:</option>
    <option value="Olympa" >Olympa</option>
    </select>
    </form>
    <br />
    <div id="txtHint" class='sortable'><b>Person info will be listed here.</b></div>

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nydiann View Post
    Code JavaScript:
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    Okay, here is the code you were asked to add.

    Code javascript:
    sorttable.makeSortable(document.getElementById('the_table_id'));

    If txtHint contains the table to be sorted, you can combine it with the above code, like this:

    Code javascript:
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        sorttable.makeSortable(document.getElementById('txtHint'));
        }
      }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Already tried it , but unfortunately with no effect at all.

    Could you look at this sorttable javascript code?
    Cause maybe it's wrong called , or anything else.

    http://www.kryogenix.org/code/browse...e/sorttable.js

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Typically the problem is not with the vendor, especially when they claim, and provide examples of, how to achieve the end result.

    What will be more instructive is for us to investigate a working example of your non-working web page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What then?

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nydiann View Post
    What then?
    Then, when we have a way to experience the non-working way that things are going for you, we can help you to get it going.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks anyway.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •