Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
761b0c7f
Commit
761b0c7f
authored
18 years ago
by
Neil Drumm
Browse files
Options
Downloads
Patches
Plain Diff
#94058
by hunmonk. Allow for multiple sortable tables on a page.
parent
5f6d48d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/tablesort.inc
+27
-14
27 additions, 14 deletions
includes/tablesort.inc
includes/theme.inc
+5
-2
5 additions, 2 deletions
includes/theme.inc
with
32 additions
and
16 deletions
includes/tablesort.inc
+
27
−
14
View file @
761b0c7f
...
...
@@ -12,10 +12,14 @@
/**
* Initialize the table sort context.
*/
function
tablesort_init
(
$header
)
{
$ts
=
tablesort_get_order
(
$header
);
$ts
[
'sort'
]
=
tablesort_get_sort
(
$header
);
$ts
[
'query_string'
]
=
tablesort_get_querystring
();
function
tablesort_init
(
$header
,
$id
)
{
if
(
strlen
(
$id
)
>
0
)
{
$id
=
'-'
.
$id
;
}
$ts
=
tablesort_get_order
(
$header
,
$id
);
$ts
[
'sort'
]
=
tablesort_get_sort
(
$header
,
$id
);
$ts
[
'query_string'
]
=
tablesort_get_querystring
(
$id
);
$ts
[
'id'
]
=
$id
;
return
$ts
;
}
...
...
@@ -31,13 +35,16 @@ function tablesort_init($header) {
* @param $before
* An SQL string to insert after ORDER BY and before the table sorting code.
* Useful for sorting by important attributes like "sticky" first.
* @param $id
* A unique id used to identify the table. Use this in the case where
* multiple tables appear on one page.
* @return
* An SQL string to append to the end of a query.
*
* @ingroup database
*/
function
tablesort_sql
(
$header
,
$before
=
''
)
{
$ts
=
tablesort_init
(
$header
);
function
tablesort_sql
(
$header
,
$before
=
''
,
$id
=
''
)
{
$ts
=
tablesort_init
(
$header
,
$id
);
if
(
$ts
[
'sql'
])
{
$sql
=
db_escape_string
(
$ts
[
'sql'
]);
$sort
=
drupal_strtoupper
(
db_escape_string
(
$ts
[
'sort'
]));
...
...
@@ -78,7 +85,7 @@ function tablesort_header($cell, $header, $ts) {
if
(
!
empty
(
$ts
[
'query_string'
]))
{
$ts
[
'query_string'
]
=
'&'
.
$ts
[
'query_string'
];
}
$cell
[
'data'
]
=
l
(
$cell
[
'data'
]
.
$image
,
$_GET
[
'q'
],
array
(
'title'
=>
$title
),
'sort='
.
$ts
[
'sort'
]
.
'&order='
.
urlencode
(
$cell
[
'data'
])
.
$ts
[
'query_string'
],
NULL
,
FALSE
,
TRUE
);
$cell
[
'data'
]
=
l
(
$cell
[
'data'
]
.
$image
,
$_GET
[
'q'
],
array
(
'title'
=>
$title
),
'sort
'
.
$ts
[
'id'
]
.
'
='
.
$ts
[
'sort'
]
.
'&order
'
.
$ts
[
'id'
]
.
'
='
.
urlencode
(
$cell
[
'data'
])
.
$ts
[
'query_string'
],
NULL
,
FALSE
,
TRUE
);
unset
(
$cell
[
'field'
],
$cell
[
'sort'
]);
}
...
...
@@ -121,12 +128,14 @@ function tablesort_cell($cell, $header, $ts, $i) {
/**
* Compose a query string to append to table sorting requests.
*
* @param $id
* A unique id used to identify the table.
* @return
* A query string that consists of all components of the current page request
* except for those pertaining to table sorting.
*/
function
tablesort_get_querystring
()
{
return
drupal_query_string_encode
(
$_REQUEST
,
array_merge
(
array
(
'q'
,
'sort'
,
'order'
),
array_keys
(
$_COOKIE
)));
function
tablesort_get_querystring
(
$id
)
{
return
drupal_query_string_encode
(
$_REQUEST
,
array_merge
(
array
(
'q'
,
'sort'
.
$id
,
'order'
.
$id
),
array_keys
(
$_COOKIE
)));
}
/**
...
...
@@ -134,13 +143,15 @@ function tablesort_get_querystring() {
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @param $id
* A unique id used to identify the table.
* @return
* An associative array describing the criterion, containing the keys:
* - "name": The localized title of the table column.
* - "sql": The name of the database field to sort on.
*/
function
tablesort_get_order
(
$headers
)
{
$order
=
isset
(
$_GET
[
'order'
])
?
$_GET
[
'order'
]
:
''
;
function
tablesort_get_order
(
$headers
,
$id
)
{
$order
=
isset
(
$_GET
[
'order'
.
$id
])
?
$_GET
[
'order'
.
$id
]
:
''
;
foreach
(
$headers
as
$header
)
{
if
(
isset
(
$header
[
'data'
])
&&
$order
==
$header
[
'data'
])
{
return
array
(
'name'
=>
$header
[
'data'
],
'sql'
=>
$header
[
'field'
]);
...
...
@@ -170,12 +181,14 @@ function tablesort_get_order($headers) {
*
* @param $headers
* An array of column headers in the format described in theme_table().
* @param $id
* A unique id used to identify the table.
* @return
* The current sort direction ("asc" or "desc").
*/
function
tablesort_get_sort
(
$headers
)
{
if
(
isset
(
$_GET
[
'sort'
]))
{
return
(
$_GET
[
'sort'
]
==
'desc'
)
?
'desc'
:
'asc'
;
function
tablesort_get_sort
(
$headers
,
$id
)
{
if
(
isset
(
$_GET
[
'sort'
.
$id
]))
{
return
(
$_GET
[
'sort'
.
$id
]
==
'desc'
)
?
'desc'
:
'asc'
;
}
// User has not specified a sort. Use default if specified; otherwise use "asc".
else
{
...
...
This diff is collapsed.
Click to expand it.
includes/theme.inc
+
5
−
2
View file @
761b0c7f
...
...
@@ -712,10 +712,13 @@ function theme_submenu($links) {
* An array of HTML attributes to apply to the table tag.
* @param $caption
* A localized string to use for the <caption> tag.
* @param $id
* A unique id used to identify the table. Use this in the case where
* multiple tables appear on one page.
* @return
* An HTML string representing the table.
*/
function
theme_table
(
$header
,
$rows
,
$attributes
=
array
(),
$caption
=
NULL
)
{
function
theme_table
(
$header
,
$rows
,
$attributes
=
array
(),
$caption
=
NULL
,
$id
=
''
)
{
$output
=
'<table'
.
drupal_attributes
(
$attributes
)
.
">
\n
"
;
if
(
isset
(
$caption
))
{
...
...
@@ -724,7 +727,7 @@ function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
// Format the table header:
if
(
count
(
$header
))
{
$ts
=
tablesort_init
(
$header
);
$ts
=
tablesort_init
(
$header
,
$id
);
$output
.
=
' <thead><tr>'
;
foreach
(
$header
as
$cell
)
{
$cell
=
tablesort_header
(
$cell
,
$header
,
$ts
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment