Numeric Sort

Numeric Sort

plwplw Posts: 34Questions: 13Answers: 0

How do I get the seond column to sort numerically please? I have tried this but it isn't working

$(document).ready(function () {
$(".UseDataTables").dataTable({ "bFilter": false,
"aaSorting": [[1, "asc"]],
"aoColumns": [
{ "bSortable": false }, // <-- disable sorting
{ "sType": "numeric" },
null,
null,
null,
null,
null,
{ "bSortable": false }, // <-- disable sorting
]
});
});

It starting of ascending which is correct but tehn I can't change the order of that column - thanks

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    You should never need to set the columns.type option. If DataTables doesn't auto-detect it, then it won't be able to sort it, even if you force it to use numeric type.

    Since there is something else happening here and as noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Allan

  • plwplw Posts: 34Questions: 13Answers: 0

    I have just tried

    $(document).ready(function () {
    $(".UseDataTables").dataTable({ "bFilter": false,
    "aaSorting": [[1, "asc"]],
    "aoColumns": [
    { "bSortable": false }, // <-- disable sorting
    { "type": "num" },
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    { "bSortable": false }, // <-- disable sorting
    ]
    });
    });

    But still not working

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    Please read Allan's reply above.

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Do you have something other than numbers in that column? If the type detection Allan described doesn't work then you likely have other types of data in that column.

    Kevin

  • plwplw Posts: 34Questions: 13Answers: 0

    Does this help?

    Ltd
    DataTables debugger
    Table information
    Summary information about the DataTables on this page.
    Information about 1 table available

    DataTables_Table_0

    Data source: Ajax
    Processing mode: Client-side
    Draws: 1
    Columns: 11
    Rows - total: 12
    Rows - after search: 12
    Display start: 0
    Display length: 10
    Version check
    Check to see if your page is running the latest DataTables software.
    LibraryInfoInstalledLatest
    DataTablesNew version available1.9.41.10.22
    AutoFill -2.3.5
    Buttons -1.6.4
    ColReorder -1.5.2
    Editor -1.9.5
    FixedColumns -3.3.2
    FixedHeader -3.1.7
    KeyTable -2.5.3
    Responsive -2.2.6
    RowGroup -1.1.2
    RowReorder -1.2.7
    Scroller -2.0.3
    Select -1.3.1
    Check for common issues
    Run automated tests to check for common and previously reported issues.
    Upload configuration data
    Upload your table's configuration and data to allow for further analysis.
    It can often greatly assist in debugging a table if we can see the configuration and data in the table. This feature of the debugger will read your local DataTables configuration and upload it to debug.datatables.net for inspection.

    Important: The data uploaded to the server can only be viewed by SpryMedia employees will be automatically deleted after two weeks. The data will never be sold or otherwise published. It is used for debugging any issues you are experiencing with DataTables only.
    Upload complete - eronep
    Your debug code is shown above. Please include this in any support requests.

  • plwplw Posts: 34Questions: 13Answers: 0

    I also have another problem. The first <tr> entry is hidden which is causing the count to be one out. s there a way of doing something about that? I thought that was causing the sort problem but it is still wrong even when I remove that <tr> entry

  • plwplw Posts: 34Questions: 13Answers: 0
    <table class="UseDataTables" border="0" cellspacing="0" cellpadding="4">
    <thead>
        <tr>
        <td>&nbsp;</td>
        <td><h2>Staff ID</h2></td>
        <td><h2>First Name</h2></td>
        <td><h2>Last Name</h2></td>
        <td><h2>Branch</h2></td>
        <td><h2>Job Title</h2></td>
        <td><h2>Phone</h2></td>
        <td><h2>Email Address</h2></td>
        <td><h2>Password</h2></td>
        <td><h2>Status</h2></td>
        <td><input type="button" value="Add New" onclick="DisplayAddNew()" name="B1"></td>
        </tr>
    </thead>
    <tbody>
       <tr id="AddRow" style="display:none;">
        <td align="center">&nbsp;</td>
        <td align="center"></td>
        <td><h4><input type="text" name="FirstName0" id="FirstName0" size="20" maxlength="50" value=""></h4></td>
        <td><h4><input type="text" name="LastName0" id="LastName0" size="20" maxlength="50" value=""></h4></td>
        <td><h4>
            <select size="1" name="Branch0" id="Branch0" required><option value="">- Select -</option>
        <%  
                rst_branch.Movefirst                                                            
                do while not rst_branch.Eof 
        %>
                    <option value='<% response.write(rst_branch.fields("Id"))%>'><% response.write(rst_branch.fields("Branch"))%></option>
        <%                                                                      
                    rst_branch.Movenext
                loop
        %>                                                                  
            </select>                                                                       
            </h4>
        </td>
        <td><h4><input type="text" name="JobTitle0" id="JobTitle0" size="20" maxlength="50" value=""></h4></td>
        <td><h4><input type="text" name="Phone0" id="Phone0" size="20" maxlength="50" value=""></h4></td>
        <td><h4><input type="text" name="EmailAddress0" id="EmailAddress0" size="20" maxlength="50" value=""></h4></td>
        <td><h4><input type="text" name="Password0" id="Password0" size="20" maxlength="50" value=""></h4></td>
        <td><h4>
            <select name="Status0" id="Status0">
                            <option value="Activated">Activated</option>
                <option value="Deactivated">Deactivated</option>
            </select>
            </h4>
        </td>
        <td><input type="button" value="Save" onclick="JavaScript: UpdateStaff(0)" name="Save"></td>
       </tr> 
       <%
        Do Until rstList.EOF
       %>
           <tr>
            <td align="center"><img border="0" src="../../icons/DUSTBIN-SML.png"  title="Delete"  onclick="Delete(<% = rstList.Fields("StaffID") %>)"></td>
            <td><h4><% response.write(trim(rstList.Fields("StaffID"))) %></h4></td>
            <td><h4><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("FirstName")))) %></span><input type="text" name="FirstName<% = rstList.Fields("StaffID") %>" id="FirstName<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("FirstName")))) %>"></h4></td>
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("LastName")))) %></span><h4><input type="text" name="LastName<% = rstList.Fields("StaffID") %>" id="LastName<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("LastName")))) %>"></h4></td>
            <td><h4>
                <select size="1" name="Branch<% = rstList.Fields("StaffID") %>" id="Branch<% = rstList.Fields("StaffID") %>" required>
                    <option value="">- Select -</option>
                    <%  
                    rst_branch.Movefirst                                                            
                    do while not rst_branch.Eof                                                                             %>
                        <option value="<% response.write(rst_branch.fields("Id"))%>" <% if trim(rstList.Fields("Branch")) = trim(rst_branch.fields("Id")) Then Response.Write("selected") End If %> ><% response.write(rst_branch.fields("Branch"))%></option>
                   <%                                                                       
                        rst_branch.Movenext
                    loop
                   %>                                                                   
                </select>                                                                       
                </h4>
            </td>                                                                           
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("JobTitle")))) %></span><h4><input type="text" name="JobTitle<% = rstList.Fields("StaffID") %>" id="JobTitle<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("JobTitle")))) %>"></h4></td>
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("Phone")))) %></span><h4><input type="text" name="Phone<% = rstList.Fields("StaffID") %>" id="Phone<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("Phone")))) %>"></h4></td>
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("EmailAddress")))) %></span><h4><input type="text" name="EmailAddress<% = rstList.Fields("StaffID") %>" id="EmailAddress<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("EmailAddress")))) %>"></h4></td>
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("Password")))) %></span><h4><input type="text" name="Password<% = rstList.Fields("StaffID") %>" id="Password<% = rstList.Fields("StaffID") %>" size="20" maxlength="50" value="<% response.write(trim(Server.HTMLEncode("" & rstList.Fields("Password")))) %>"></h4></td>
            <td><span style="display: none"><% response.write(trim(Server.HTMLEncode("" & rstList.Fields("Status")))) %></span><h4>
                <select name="Status<% = rstList.Fields("StaffID") %>" id="Status<% = rstList.Fields("StaffID") %>">
                    <option <% If rstList.Fields("Status") = "Activated" Then Response.Write("selected") End If %> value="Activated">Activated</option>
                    <option <% If rstList.Fields("Status") = "Deactivated" Then Response.Write("selected") End If %> value="Deactivated">Deacativated</option>
                </select>
                </h4></td>
            <td><input type="button" value="Update" onclick="JavaScript: UpdateStaff(<% = rstList.Fields("StaffID") %>)" name="Update"></td>                           </tr> 
        <%
                   rstList.MoveNext
                Loop 
            %>
    

    </tbody>
    </table>

    Is the table

  • plwplw Posts: 34Questions: 13Answers: 0

    I have moved the Add new entry to a seperate table which has solved the count problem so it is now just the numeric sort which is a problem

  • plwplw Posts: 34Questions: 13Answers: 0

    Problem solved - it doesn't like the

    surrounding it

This discussion has been closed.