I have created my first module. I am running into an issue with my table. The headers and the row text don’t line up and the header row are not sortable
See the image, the top example shows the “Disk and Network Filesystems” Module the headers are lined up with the rows and they have those sort arrows.
My table the headers don’t line up and they are not sortable. I have searched all over to find how to do this.
Here is my code
#!/usr/bin/perl
use DBI;
use lib "/usr/libexec/webmin/client_management";
use client_management qw(read_db_config);
require './client_management-lib.pl';
# Read database configuration
my %config = read_db_config("/usr/libexec/webmin/client_management/db_config.conf");
my $dsn = "dbi:Pg:dbname=$config{db_name};host=$config{db_host}";
my $dbh = DBI->connect($dsn, $config{db_user}, $config{db_pass}, { RaiseError => 1, AutoCommit => 1 })
or die "Database connection failed: $DBI::errstr\n";
# Webmin UI header
#print &header("Client Management", undef);
print &ui_print_header("", $module_info{'desc'}, "", undef, 1, 0, 0);
# Fetch all records from the client table
my $sth = $dbh->prepare("SELECT id, name FROM client");
$sth->execute();
my $client_array = $sth->fetchall_arrayref;
# Sort by id (alphabetical)
my @sorted_id = sort { $a->[0] cmp $b->[0] } @$client_array;
if (@sorted_id) {
print &ui_columns_start([ $text{'index_id'},
$text{'index_email'},
$text{'index_clname'},
$text{'index_dparts'}]);
# Output the sorted records
foreach $idrec (@sorted_id) {
my ($id, $name) = @$idrec;
my $view_link = "<a href='view.cgi?id=$id'>$id</a>";
my $emails_link = "<a href='emails.cgi?id=$id'>$text{'emails_link'}</a>";
print &ui_columns_row([$view_link, $emails_link, $name]);
}
$sth->finish();
$dbh->disconnect();
print &ui_columns_end();
}
# Cleanup
&ui_print_footer("/", $text{'index'});
#print footer();
No ideas? This is driving me nuts. I have researched and tried this…
Core Webmin API web-lib-funcs.pl Common functions for Webmin scripts. This file gets in-directly included by all scripts that use web-lib.pl.
use WebminCore; init_config(); ui_print_header(undef, 'My Module', ''); print 'This is Webmin version ',...
Its the only thing in a table the discusses sorting. No luck
Ilia
March 16, 2025, 6:51pm
3
Hello,
There was no such API until now. With the upcoming Webmin 2.303 release, you will be able to add the following key to your module.info
:
sortable=1
…which will make tables in the module sortable.
If you want to try this feature immediately, you can download the latest development version of Webmin:
Joe
March 16, 2025, 6:54pm
4
How does that work with a module that also has tables that can’t be sorted (like, showing the order of rules in a file that are checked in order)?
Ilia
March 16, 2025, 6:56pm
5
It will fail by catching and throwing a warning to the browser’s console, explaining the problem. Procmail is an example of such a failure.
Ilia
March 16, 2025, 7:07pm
6
@ljprevo By the way, for this to work in the first place, a module must use ui_columns_start
or ui_hidden_table_start
to trigger initialize process for the sortable tables—it won’t apply to just any table on the page.
If neither ui_columns_start
nor ui_hidden_table_start
is used, the table should have the table
class set to enable sortable headers.
And, if an eligible table in the module is broken, for instance, if there is an inconsistent number of table head elements compared to table body elements, a warning will be thrown to the browser’s console without breaking further code execution.
How do you set the table class? I don’t see anything in the docs.
Also I am using ui_columns_start still not getting sortable headers.
Ilia
March 16, 2025, 8:46pm
9
You don’t need to set anything if you use ui_columns_start
.
I did, still does not work
Ilia
April 20, 2025, 8:11pm
11
It would be helpful if you could tell us which versions of Webmin and the Authentic theme you are running, as well as the specific code you tried that didn’t work.