What plug-in will work for me?

What plug-in will work for me?

gmarshall56gmarshall56 Posts: 15Questions: 6Answers: 0

Hello:

The first column in my dataTables will contain numbers however in one row the number will have an asterisk (*) concatenated to it, for example: "20**". Of course this is throwing the sort of this column off. Can someone please tell me what plug-in I can use so that the column will sort as if all of the data is numbers? If I were to configure the column in question in my internal table that is used to populate the dataTable so that it always is, say four characters long with the first three characters always being numbers could there perhaps exist a plugin that allows me to tell dataTables to sort only on these first three characters even though the data for that column has four characters? Thank you for your assistance. Gary

This question has an accepted answers - jump to answer

Answers

  • gmarshall56gmarshall56 Posts: 15Questions: 6Answers: 0

    Update: I found your "Percentage" plugin which I think will work. I'm trying to replace this line of code:
    var x = (a == "-") ? 0 : a.replace( /%/, "" );

    with:
    var x = (a == "-") ? 0 : a.replace( //, "" );
    ...but the javascript compiler is complaining because I think it thinks I'm trying to place a javascript comment in there (
    /.../). Can you please let me know how to update this line of code to specify to replace the asterisk () with ""?

    Again, Thanks for your time.
    Gary

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin

    How about:

    var x = (a == "-") ? 0 : a.replace( /\*/, "" );
    

    I just tried it on my console and it seems to work okay.

    Allan

  • gmarshall56gmarshall56 Posts: 15Questions: 6Answers: 0

    Allen:
    Thank you for your input. I tried the "Percentage" plug-in without success. Its quite possible I am not coding this the correct way. Could you please take a look at the code I have at http://live.datatables.net/soyikos/2/edit ? As a reminder, I am trying to sort that column of data that can contain up to a 3-digit number with one row having an asterisk (*) concatenated to the number. As you can see in my code so far dataTables is sorting the data by the first character in the array only. Thanks in advance for your assistance in getting this to work. Gary PS: Please apologize to soyikos if I have destroyed his test case. It was an accident made by a noobie.. :>) Also... I noticed that my link...http://live.datatables.net/soyikos/2/edit... does not generate in IE but it does in Firefox. This is not that important right now, but I wonder why?

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin

    I think the issue in that example is with the data that is being passed in. An array of strings, while DataTables is expecting an array of arrays, or an array of objects. Making it so allows it to work: http://live.datatables.net/soyikos/3/edit

    The reason for this, is that typically you will have more than one data point in each row (i.e. more than one column) - hence the use of inner arrays or object.

    You can, as of 1.10, tell DataTables to use the data directly, that would allow the format that you used (set columns.data to null) but its rare that you would only have one column I think, hence my suggestion here.

    Regards,
    Allan

  • gmarshall56gmarshall56 Posts: 15Questions: 6Answers: 0

    Thank you again for your attention. I agree, an array typically has more than one column. I just created an array with one column in my example only so that you could show me how to get the sort to work with an asterisk in that column. Thanks again. In this example: http://live.datatables.net/soyikos/6/edit I added another column and a "aoColumns" property to the DataTable initialization. It works well however I am getting a message at the bottom of the JS Bin stating: "Line 6: aoColumns:[-- Mixed spaces and tabs.", and I noticed that the "sWidth" parameters are not being applied. Can you please advise? Thank you. Gary

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin

    "Line 6: aoColumns:[-- Mixed spaces and tabs."

    That means exactly what it says. Some of the code has tabs and spaces for indent which is bad practice. The linter is harsh :-)

    and I noticed that the "sWidth" parameters

    They are, however, table has width:100% in the CSS, so what's a browser to do :-). The 100% is ~980px in that example, and 25+25 !== 980, so the browser does the sensible thing and follows the 100% and treats the 25px widths as a guide only.

    Allan

  • gmarshall56gmarshall56 Posts: 15Questions: 6Answers: 0

    In my latest example: http://live.datatables.net/soyikos/7/edit I have cut and pasted the contents of the array that my java script code in my application feeds into the initialisation of the DataTable. As you can see it works fine in the JS Bin, however the sort continues to not work in my application. My application uses
    jquery-ui-1.8.21.custom.min.js and version 1.9.4 of jquery.dataTables.js. Could it be that my application is not producing the same results as I see in JS Bin because I am not using the correct versions of the javascript files? Perhaps this is a silly question, but I must be sure. Thank you again, sir. Gary

  • allanallan Posts: 54,914Questions: 1Answers: 8,608 Site admin
    Answer ✓

    version 1.9.4 of jquery.dataTables.js

    You are using DataTables 1.10 naming though... So 1.9.4 isn't going to see your column definitions. See http://legacy.datatables.net/usage for the 1.9 naming scheme. If you can upgrade to 1.10, I would suggest you do so as 1.9 is no longer supported.

    Allan

This discussion has been closed.