What determines the number of columns in Datatables based datatable? - datatables

I am new to the DataTables plugin,
How does it determine the number of columns to display?
Based on the HTML table? or based on the DataSource?
Or is it some combination of the two ?
Can I have columns in the DataSource that are not rendered as columns?
(but are used for example as a tooltip on another column) ?

How does it determine the number of columns to display?
The answer really depends on how you configure your table (keep reading to see what I mean).
Based on the HTML table? or based on the DataSource? Or is it some combination of the two ?
If you create a DOM based HTML table with all of your data already in it, then you can see from the zero configuration example that it will just display all of your columns that are provided.
Can I have columns in the DataSource that are not rendered as columns? (but are used for example as a tooltip on another column) ?
You can further configure the table to hide certain columns using the bVisible parameter in the aoColumnDefs or aoColumns settings for the table configuration. See this example for how to hide columns.
You can then use mrender to render a column in a particular way.
Say your data had two columns, ID and Name and you wanted to have Name be displayed but only show the ID as a tooltip when the user mouses over the Name cell. In your aoColumns object, set bVisible to false for the ID column and set mrender for the Name column as follows:
"mrender": function(data, type, full) {
return '<span title="' + full.ID + '">' + data + '</span>';
}
Note that if you're using a data source other than the data embedded in the DOM at load (such as AJAX) you're going to probably want to also specify the mdata parameter for each aoColumns definition, as can be seen in this example.
Best of luck!

Related

bootstrap-vue table with sorting inside page

I have a bootstrap-vue table with pagination.
When I sort data by clicking a column header, data is sorted globally, which means that page N of a sort-by-column-one table displays different data than page N of a sort-by-column-2 table.
I would like to have an additional internal per-page sorting, e.g. via two separate column header rows. The first one would be responsible for global sorting, the other one would only (re-)sort displayed data of the current page.
Is there a standard way to do this?

sm30: Set matching column heading

I created a table in SAP via se11, then I used the table maintenance generator.
Now I edit the table via sm30:
The second and the third column: Both have the heading "Feldname".
The first "Feldname" column is called COLUMN_NAME and its data element is "Fieldname".
The second "Feldname" column is called AUTH_FIELD and its data element is "XUFIELD"
I would like to see the column names which I gave the columns in se16 (COLUMN_NAME, AUTH_FIELD) in the heading.
How to prevent the table maintenance generator from giving other names in the headings?
Option 1 - use custom data elements:
Instead of using Fieldname and XUFIELD data elements, you can create your custom data elements and give them what header you would like.
(You will have to regenerate table maintenance)
Option 2 - editing screen
When generated the table maintenance, you supplied a function group and a screen number.
Go to SE80 -> Function Groups -> <function_group_supplied> -> screens -> <screen_supplied>.
Then edit it as you want.
Note: Modifying a generated object is considered risky. Your customized changes might be overwritten in a future regeneration.
Add custom data elements with suitable descriptions. Let the new data elements refer to the original ones (resp. the domains) to avoid having to reinvent everything.
Data element descriptions can be translated.
You can set different descriptions for different lengths, e.g. "Field" for the narrow column with length 10, and "Field name" for a wide label with length 30.
Regenerating the maintenance screen won't accidentally delete the changed descriptions.

WebDriver - locate dynamic column

I am using webdriver to test our application that contain table where the user can change the order of columns in a table,and also can remove/add columns (This is beside new column added by developers).
What is the right way to find the column I need?
One way is to go over the table header to find the column I am looking for so I have the column index and than I can access the right cell.
Is there other way ?
What about put unique id/class name for every element in table ?
Thanks
You can do two things for this situation:
Get handle to table element, and then navigate accordingly to get the columns or rows. Once you have this, then you can do all operations on them like click() etc.
Other way is, see the pattern of their ids/css because, most of the table that I have deal with will be having ids like this:
grid_name_1
grid_name_2
grid_name_3
Then you can have do this way:
String baseLocator = "grid_name_" + clickedRowIndex;
driver.findElement(By.id(baseLocator)).click(); //for click operation
Lets say user wants to click on the 3rd row, then clickedRowIndex will be 3 which selects the 3rd table row.

How to use query for grid\enhancedGrid?

I want to sort information in a dojo EnhancedGrid (connected to database through JsonRestStore). I know dojo grids provide functionality to sort based on a single column. However, in my grid, one column contains combined information from multiple fields (e.g., last name, first name, email, age) of database table. Is there a simple way to sort the grid or the data in the store based on a single filed in database table (e.g., last name)?
It seems I can use "query" to change the view of the store (grid is a view of the store if I understand correctly), but I don't understand how to write a query to do that. Can anyone give me more information about the syntax of using query or how to solve this issue?
Thank you!
It looks like you have to use what is called a comparatorMap for customized grid sorting.
here's one example :
http://www.ibm.com/developerworks/web/library/wa-aj-dojogrid/index.html
(look for the section 'Listing 15. Customize the sort function of Dojo
Grid')
inside the comparator map function is where you would convert the strings to
numbers and make the numeric comparison.

Display Hyperlink field on rows based on value from the database

How do I dynamically display the 'Edit' on the hyperlink field based on the values on the rows, generated from the database.
N/B.: the gridview automatically generates rows.
Do you mean you want a DataGridViewLinkColumn in the grid with Edit displayed if appropriate? Like this:
In which case, make the whole column a LinkColumn and whether or not it's clickable will be taken care of internally by the grid. Columns which don't display Edit will not be clickable.
If you don't mean this then please provide more detail.