Using DataTables without thead tag. Perform sorting and filtering via dropdown menu with ui li tags.
Using DataTables without thead tag. Perform sorting and filtering via dropdown menu with ui li tags.
Hi,
I am new to jQuery and DataTables. From what I have researched so far, I have found out that DataTables can be a very good solution for dealing with tables.
Right now, I am populating the table using 2 different web services and I have to query the 2nd web service based on an attribute present in the first one. In the table I need to display data from both of these web services. I am creating a dynamic table with the data coming from the server using jQuery. I have the dropdowns created in separate divs using ui li structure. Now each of the individual columns are below one of these divs and based on the dropdown these columns should be sorted. Also I need to specify a default sorting order based on one column.
I have the following questions:
1. Can we create table using 2 different web service using dataTables since we have to include attributes from both of those.
2. Can we create data tables without thead tag or is it possible to hide thead tags if we cannot do it without them as I have drop downs to perform sorting and filtering on individual columns. Also I need to paginate the data in tables is it possible without thead.
3. Since I have separate drop downs for sorting and filtering is it possible to use a selector other than thead tags for performing the same.
Please direct me to any relevant posts if any. Please suggest me some work around if above does not work like the requirement.
Thanks.
- kunal
I am new to jQuery and DataTables. From what I have researched so far, I have found out that DataTables can be a very good solution for dealing with tables.
Right now, I am populating the table using 2 different web services and I have to query the 2nd web service based on an attribute present in the first one. In the table I need to display data from both of these web services. I am creating a dynamic table with the data coming from the server using jQuery. I have the dropdowns created in separate divs using ui li structure. Now each of the individual columns are below one of these divs and based on the dropdown these columns should be sorted. Also I need to specify a default sorting order based on one column.
I have the following questions:
1. Can we create table using 2 different web service using dataTables since we have to include attributes from both of those.
2. Can we create data tables without thead tag or is it possible to hide thead tags if we cannot do it without them as I have drop downs to perform sorting and filtering on individual columns. Also I need to paginate the data in tables is it possible without thead.
3. Since I have separate drop downs for sorting and filtering is it possible to use a selector other than thead tags for performing the same.
Please direct me to any relevant posts if any. Please suggest me some work around if above does not work like the requirement.
Thanks.
- kunal
This discussion has been closed.
Replies
2. no can't use DataTables without THEAD, but you can hide it if you want
3. yes. you can programatically sort (see http://www.datatables.net/ref#fnSort ) so you could use any control you want that responds to whichever event you want by triggering fnSort.
Can you give me any example of hiding the thead. I think I can use jQuery.hide() for doing that, but I need to look into it. More suggestions are welcome.
if you're using sScrollX/sScrollY be aware that the header is copied out and put into a separate header, so you'll want to .hide() that as well.
I have put the thead tags and tried to initialize table under $(document).ready() using the code below. I am not using dataTables to create the table and populate it dynamically, it is done using ajax call in success of another ajax call.
So I am creating a table first which is getting displayed in html and then applying datatables to it. But the table is not getting displayed with the options below. In fact datatable is not getting applied to it.
Please suggest whats going wrong here.
[code] var oTable = $('#table_id').dataTable({
"bDestroy":true,
"aaSorting": [[2,'asc'], [3,'asc']],
"sPaginationType": "full_numbers",
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false
});
[/code]
Edit: With the above call still present in my code and not able to apply dataTable to it. I just tried using javascript console in chrome and ran the same above code and it seems to work fine like that. It was showing the table formatted with the pagination, sorting and search feature. I am wordering how to initialize it in my html file.
I could be going wacky, though. This has been known to happen.
Thanks for the reply. I have used bDestroy: true only while running it from the console on chrome as it datatables was giving some error, but I will try it without that also. In my actual development code I have not used bDestroy: true. I am calling [code] oTable = $('#table_id').dataTable(); [/code] after finishing all the ajax calls and building the table to initialize datatables. In this case, dataTables is not getting applied.
I have tried putting the above code in the success call of first ajax call within which the table is getting constructed dynamically using getJSON call. Here I can see the dataTables being applied but it shows only the 1st 10 records of the table that is being formed dynamically.
Please suggest if you have come across this problem before.
Thanks,
Kunal
So I made a call using setTimeOut() function with 500ms timer, and I found that the datatable is applied. But instead of showing 10 rows in default mode [code] $('#table_id').dataTable();[/code], it is only showing 9 rows.
Again, I would like to ask:
1. If applying datatable on a dynamically created table is a better approach or directly using datatables API for forming the table dynamically is better? As it takes time for initialization step and the raw table is shown first than styled table.
Also I think I would have to put customization and other features in setTimeOut function as those changes won't be applied unless the table is formed.
Please give some suggestions as to which approach is better in my scenario.
Thanks.