How to sort the serial numbers while the other columns get sorted?
How to sort the serial numbers while the other columns get sorted?
suresh22
Posts: 7Questions: 1Answers: 0
Check the below link
https://datatables.net/examples/api/counter_columns.html
So other than the first column(Serial Number) the other columns are getting sorted by the sort arrow keys at the top of each column. But here the serial numbers are not getting sorted but the other columns does. Could you please help me to get sort the serial numbers along with the other columns?
This discussion has been closed.
Answers
The way I am reading your request, it sounds like you simply want the column with your serial numbers to not be sortable, and move with the rest of your data when you sort other columns? If that is the case, you don't want to use that example and you should just build a regular table but disable the sort for that one column. If that is not the case then I'm not sure what you are asking exactly.
Also it would help if you posted your code so we can see what you are doing.
Thank you for your response. You misunderstood the statement as the "serial numbers to not be sortable". But I want it to be also sortable.
Example when you check the link I posted, there are 6 columns. In the second column(Name), there is an up arrow where the sorting could be controlled right. I need a same up arrow in the serial number column(very first column), Almost there are 57 results when I click on the arrow, the 57th result should come on top, showing the starting serial number as 57, 56, and so on till 1. I hope now you understand. I am using server side scripting with this. Serial number column I am just looping and printing the row index number, but the other column results are displaying from the database, when i click on the sorting control arrow, everything other than the serial column is reversing up , but the serial number column is not reversing up. I just want it to be also reversing.
The example you linked to clearly states that "This column should not be sortable". I don't understand what behaviour you are expecting.
If you want a column of numbers to be sortable, simply include those numbers in the data source just like any other data point in the table. The example you link to is, as tangerine notes, specifically designed to show calculated numbers in the first column, not data from the source. I would say that example is completely irrelevant for what you want.
Allan
Check this fiddle
http://jsfiddle.net/rt24sm20/1/
This is the code i am using. The data are dummy. But I am using php loop for getting data from DB. Only the index column(very first column) is automatic[not from DB]. See my jquery code. SO if you click on the title date or eo number or total amount, the data will get reversed, but when you click on serial number column nothing is reversed. I want serial no. column also to be reversed while clicking on it. Hope you guys are clear now.
Please let me know if needed further clarification.
Thanks
I was going to suggest what allan suggested. You should just make the table normal but use your data as the S.No. I changed your fiddle as an example.
hello ignignokt,
So we can not use auto generated numbers for sorting? Like the example I showed you
http://jsfiddle.net/rt24sm20/1/
You just entered the serial numbers manually that I cannot do it, as we can have more number of rows.
Sure you can use auto generated numbers for sorting, but you can't use my example you linked to for sorting since the sorting defines those numbers! I would suggest completely forgetting that example, it will not help you here!
The question is - how do you want to define a number of each row in the table? Why can't you just put that number in the data?
Allan
what do you mean by data? You mean inside the table? Yes I do generate the numbers. Even I don't need sorting, if you see the above fiddle, why the serial numbers are not reversed while the other data columns get reversed, when I auto generate the numbers?
In the example you linked to it does sort by the numbers because as I said above, the sorting defines the numbers. As I also said, forget the example you linked to - it will not help you here. The example is explicitly to show row numbers in the order applied to the table. I repeat - the numbers in the first column cannot be sorted because the sorting defines those numbers.
When I say "Data" why not just put 1, 2, 3 etc into the table in the HTML like you have for everything else.
Allan
Because I use server side scripting. How I can put numbers for if say have 1000 rows? You got what I mean? Any idea?
You mean to say like a loop for each rows. Yes I can put, but the problem is I am using a hidden column id field to show the results added in the table in descending order. So even if I add a loop, the serial numbers are also in reverse order.
So why not just count down when adding the numbers rather than adding up?
Allan