# Table Overview

# columns()

Set table field names to display.

Parameter Type Default Description
$columns mixed '' Comma separated string of table field names or an array of field names.
$reverse boolean false Hides the field names in $columns if set to true.
$xcrud->columns('name,email,city');
//or
$xcrud->columns(array('name','email','city'));
 
// hide columns
$xcrud->columns('name,email,city', true);

# order_by()

ORDER BY clause. Applies for only one field and it's sort order. Multiple calls can be made for each field in the ORDER BY clause.

Parameter Type Default Description
$fields string '' Field name or an associative array of field => direction pairs..
$direction string 'asc' Sorting order only if $fields is a string.
Accepted values: 'asc' or 'desc'
$xcrud->order_by('name'); // ORDER BY name ASC
$xcrud->order_by('city','desc');  // ORDER BY name ASC, city DESC
// or
$xcrud->order_by(array('name', 'city' => 'desc')); // ORDER BY name ASC, city DESC

# label()

Set field name aliases.

Parameter Type Default Description
$fields mixed '' Table field name or an associative array of field => alias pairs.
$label string '' Field name alias only if $fields is a string.
$xcrud->label('name','Your Name'); // name AS 'Your Name'
// or
$xcrud->label(array('name' => 'Your Name')); // name AS 'Your Name'

# column_name()

List screen only. Set grid column header names. Make multiple calls for each field.

Parameter Type Default Description
$fields string '' Table field name.
$text string '' Field name alias.
$xcrud->column_name('name','Your Name'); 

# show_primary_ai_column()

Display the PRIMARY AUTO_INCREMENT field.

Parameter Type Default Description
$bool boolean true Display the PRIMARY AUTO_INCREMENT field if set to true and otherwise for false.
$xcrud->show_primary_ai_column(); 

# limit()

Set the number of rows to display per page in list view.

Parameter Type Default Description
$limit int 20 Rows to display per page in list view.
$xcrud->limit(25);

# limit_list()

Set pagination limits (limits()) options. Shown on the pagination bar at the bottom of the list screen.

Parameter Type Default Description
$limit_list mixed '' Comma separated string or an array of strings.
Also accepts the option 'all'; displays the entire result set.
$xcrud->limit_list('5, 10, 15, all');
// or
$xcrud->limit_list(array('5', '10', '15', 'all'));

# table_name()

Set table title.

See 'default' theme icons

Parameter Type Default Description
$name mixed '' Table title.
$tooltip mixed false Icon tooltip (on mouse hoover over the icon).
$icon mixed false Icon name from the default theme.
$xcrud->table_name('My custom table!');
$xcrud->table_name('My custom table!', 'Some tooltip text','icon-leaf');

// no icon specified. a ? is displayed to enable 
// viewing the tooltip on icon hover
$xcrud->table_name('My custom table!', 'Some tooltip text'); 

# unset_add()

Hides create (add) button from list view.

Parameter Type Default Description
$bool boolean true Set true to hide the create (add) button, false to show it, if already hidden.
$xcrud->unset_add(); // hide create (add) button
$xcrud->unset_add(false);  // undo action above

# unset_edit()

Hide edit buttons for all rows in list view. It can also hide the edit buttons given a condition.

Parameter Type Default Description
$bool bool true Set true to hide the edit buttons, false to show it, if already hidden.
If the other parameters below are provided, set true to hide the edit buttons for rows that meet the condition. Set false to hide the edit buttons for rows that DON'T meet the condition.
$field mixed false Conditional table field to compare with $value.
$operand mixed false Comparison operator to use on $field and $value.
$value mixed false Value to compare with $field.
$xcrud->unset_edit(); // hide all edit buttons for each row
$xcrud->unset_edit(false); // undo action above

// hide edit buttons on rows that meet the condition 
// 'postalCode = 10022'
$xcrud->unset_edit(true, 'postalCode', '=', '10022');
// or
// hide edit buttons on rows that DON'T meet the condition 
// 'postalCode = 10022'
$xcrud->unset_edit(false, 'postalCode', '=', '10022'); 

# unset_view()

Same as unset_edit() but hides view buttons for all rows in list view. It can also hide the view buttons given a condition.

$xcrud->unset_view(); // hide all view buttons for each row
$xcrud->unset_view(false); // undo action above

// hide view buttons on rows that meet the condition 
// 'postalCode = 10022'
$xcrud->unset_view(true, 'postalCode', '=', '10022');
// or
// hide view buttons on rows that DON'T meet the condition 
// 'postalCode = 10022'
$xcrud->unset_view(false, 'postalCode', '=', '10022'); 

# unset_remove()

Same as unset_edit() but hides delete buttons for all rows in list view. It can also hide the delete buttons given a condition.

$xcrud->unset_remove(); // hide all delete buttons for each row
$xcrud->unset_remove(false); // undo action above

// hide delete buttons on rows that meet the condition 
// 'postalCode = 10022'
$xcrud->unset_remove(true, 'postalCode', '=', '10022');
// or
// hide delete buttons on rows that DON'T meet the condition 
// 'postalCode = 10022'
$xcrud->unset_remove(false, 'postalCode', '=', '10022'); 

# unset_csv( true)

Hides csv-export button from list view.

Parameter Type Default Description
$xcrud->unset_csv();

# unset_search( true)

Hides search feature.

Parameter Type Default Description
$xcrud->unset_search();

# unset_print( true)

Hides printout feature.

Parameter Type Default Description
$xcrud->unset_print();

# unset_title( true)

Hides table title.

Parameter Type Default Description
$xcrud->unset_title();

# unset_numbers( true)

Hides rows numbers.

Parameter Type Default Description
$xcrud->unset_numbers();

# unset_pagination( true)

Hides pagination

Parameter Type Default Description
$xcrud->unset_pagination();

# unset_limitlist( true)

Hides list with limits buttons or dropdown

Parameter Type Default Description
$xcrud->unset_limitlist();

# unset_sortable( true)

Makes columns unsortable

Parameter Type Default Description
$xcrud->unset_sortable();

# unset_list( true)

Turn of grid view. Only details can be viewed or edited. Don't forget to set view parameter in render() method.

Parameter Type Default Description
$xcrud->unset_list();

# unset_view(), unset_edit(), unset_remove(), duplicate_button()

These methods can get additional condition parameters (with {field_tags})

Parameter Type Default Description
$xcrud->unset_edit(true,'username','=','admin'); // 'admin' row can't be editable

# remove_confirm( true)

Removes confirmation window on remove action. Takes true / false in the first parameter.

Parameter Type Default Description
$xcrud->remove_confirm(false);

# start_minimized(true)

Start xCRUD instance minimized. Takes true / false in the first parameter.

Parameter Type Default Description
$xcrud->start_minimized(true);

# benchmark(true)

Displays information about the performance in the lower right corner of the xCRUD window. Takes true / false in the first parameter.

Parameter Type Default Description
$xcrud->benchmark(true);

# column_cut(int, [fields])

Sets the maximum number of characters to be displayed in columns. Takes an integer value in the first parameter. In the second parameter you can define target field(s)

Parameter Type Default Description
$xcrud->column_cut(30); // all columns
$xcrud->column_cut(30,'title,description'); // separate columns

# duplicate_button(true)

Show duplicate button. You can duplicate only the records in those tables that have auto-incremental primary field, and have no other unique indexes. Otherwise you will get an error.

Parameter Type Default Description
$xcrud->duplicate_button();

Creates label for links in grid view. Takes new label in first parameter

Parameter Type Default Description
$xcrud->links_label('home url');
// or
$xcrud->links_label('<i class="icon-home"></i>'); // bootstrap icon for bootstrap theme

# emails_label( label)

Creates label for links in grid view. Takes new label in first parameter

Parameter Type Default Description
$xcrud->emails_label('Contact email');

# sum(columns, classname, custom_data)

Calculates sum for columns and shows result row in the bottom of table. Calculates sum of the entire list, regardless of pagination. Takes columns list in first parameter, optional classname in second, and optional custom text pattern in third.

Parameter Type Default Description
$xcrud->sum('price,fee,quantity');
//or
$xcrud->sum(array('price','fee','quantity'));
//or
$xcrud->sum('price','align-center','Total price is {value}'); // use {value} tag to get sum value in pattern

# button()

Adds custom link button in grid view, just like the edit or remove buttons.

Parameter Type Default Description
$link string URL to open.
$name string '' HTML Button name.
$icon string '' Predefined classname. These are icon glyphs from the bootstrap theme. See default theme icons here: xcrud/themes/default/fonts.css (opens new window)
$class string '' CSS classname.
$parameters array array() Additional HTML attributes specified as an associative array with keys named after html attributes.
$condition array array() If specified, the array should have 3 items array(field,operand,value).
The field, operand, value are the same as for unset_edit().
If the condition is met i.e. true, the button is displayed.
$xcrud->button('http://example.com');
$xcrud->button('http://example.com','My Title','icon-link','',array('target'=>'_blank'));
 
// {column_tags} usage:
$xcrud->button('http://example.com/{user_id}/?token={user_token}');

// last param $condition array('send_email','=',1)
// show button if field:send_email is equal to 1
$xcrud->button( '#', 'Send Email', 'icon-link', '', 
    array('class' => 'ajax-send', 'data-id' => '{paymentId}'), 
    array('send_email','=',1));

TIP

You can use buttons with text labels. See $button_labels parameter in configuration file

# button() {column_tags} usage:

A column tag is a string of a table fieldname (column) enclosed by curly braces i.e. '{fieldname}'.

// show button whith link from 'link' field when 'link' field is not empty
$xcrud->button('{link}','userlink','link','','',array('link','!=','')); 

# highlight( field, operator, value, color, classname)

Adds background color or class attribute for grid cell based on user's condition.

Parameter Type Default Description
$xcrud->highlight('orderNumber','=','10101','red');
$xcrud->highlight('orderNumber','>=','10113','#87FF6C');
$xcrud->highlight('city','=','Madrid','','main-city'); // you can define class attribute

Also you can get value from current row using {field_tag}

Parameter Type Default Description
$xcrud->highlight('sum', '>', '{profit}', 'red');

# highlight_row( field, operator, value, color, classname)

The same as highlight(), but full row will be highlighted

# column_class( column(s), classname)

adds class atribute to column(s).

Parameters

  • classname - can any of the following predefined classes: align-left, align-right, align-center, font-bold, font-italic, text-underline
Parameter Type Default Description
$xcrud->column_class('price,sum,count', 'align-center');

# subselect( column_name, query, before_column)

Select to other table with parameters. This will create new column and inserts it after last column in table, or before colum defined in 3rd parameter

Parameter Type Default Description
//subselect
$xcrud->subselect('Order total','SELECT SUM(priceEach) FROM orderdetails WHERE orderNumber = {orderNumber}'); // insert as last column
$xcrud->subselect('Products count','SELECT COUNT(*) FROM orderdetails WHERE orderNumber = {orderNumber}','status'); // insert this column before 'status' column

// you can use order() and change_type() for this columns;
$xcrud->change_type('Order total','price','',array('prefix'=>'$'));
$xcrud->order_by('Products count');

Also you can operate with fields only in current row

Parameter Type Default Description
$xcrud->subselect('Sum','{price}*{qty}');

Shows cell info in modal. See 'default' theme icons

Parameter Type Default Description
$xcrud->modal('customerName,customerDescription);
$xcrud->modal('customerName', 'icon-user');
$xcrud->modal(array('customerName'=>'icon-user'));

# column_pattern(column_name, pattern_code)

Replaces default column cell output by custom pattern. Pattern can contain {field_tags} and {value} tag (value of current column)

Parameter Type Default Description
$xcrud->column_pattern('username','My name is {value}');

Difference between {value} and {username} (see example): {username} will return raw value from current cell, but {value} will return full output if your field has some extra features (like image or formatted price)

# field_tooltip( field(s), tooltip_text [, icon ])

Creates tooltip icon for field label in create/edit/view mode. See 'default' theme icons

Parameter Type Default Description
$xcrud->field_tooltip('productName','Enter product name here');

# column_tooltip( column(s), tooltip_text [, icon ])

Creates tooltip icon for column label in create/edit/view mode. See 'default' theme icons

Parameter Type Default Description
$xcrud->field_tooltip('productName','Enter product name here');

# search_columns( [ column(s) ] [, default_column ])

Defines column list for search and default search column

Parameter Type Default Description
$xcrud->search_columns('productVendor,quantityInStock,buyPrice','quantityInStock');

# buttons_position( position)

Changes position of grid buttons. Can be 'left', 'right' or 'none'. 'None' option will hide buttons, their features will be available (unlike of unset_ methods). Default is 'right' and can be changed in configuration file.

Parameter Type Default Description
$xcrud->buttons_position('left');

# hide_button( button_name(s))

Hides system or your custom button(defined with render_button() method). This not disables button feature (unlike of unset_ methods).

Parameter Type Default Description
$xcrud->hide_button('save_return');

Default system buttons are: view, edit, remove, duplicate, add, csv, print, save_new, save_edit, save_return, return.

# column_width( column(s), width)

Sets width of xcrud columns manualy.

Parameter Type Default Description
$xcrud->column_width('description','65%');
$xcrud->column_width('first_name,last_name','100px'); 

# send_email_public()

Send email with xCRUD.

Parameter Type Default Description
$to string Recipient email address.
$subject string Email subject.
$message string Email message body.
$cc array() Carbon copy (cc) email to specified in string array of email addresses.
$html boolean Default email message type is HTML. Setting to false sends the email body as plain text.

Configure the following parameters in xcrud_config.php. You can get these from your email provider.

// SMPT Mail configuration in file xcrud_config.php

//Set the hostname of the mail server   
public static $mail_host = 'mail.email.com'; 
//Set the SPMT port number - likely to be 25, 465 or 587
public static $mail_port = 587; 
//Whether to use SMTP authentication
public static $smtp_auth = true; 
//Username to use for SMTP authentication
public static $username = 'xcrud17@email.com'; 
//Password to use for SMTP authentication
public static $pass = 'sTr0ng^pa55word=='; 
//Set who the message is to be sent from
public static $emailfrom = 'xCRUD Company'; 
//Sets connection prefix. Options are - "", "ssl" or "tls"
public static $smtpsecure = 'tls';

Example

$xcrud = Xcrud::get_instance();

$emailBody = "Hey there. xCRUD sends email!!";
$subject = "Email Test";

$to = "xcrud@mailinator.com";
$xcrud->send_email_public($to, $subject, $emailBody, $cc = array(), true);

echo "<br>Click <a href='https://www.mailinator.com/v4/public/inboxes.jsp?to=xcrud'>here </a>to access the email that has just been sent! <br>";
    
Last Updated: 7/13/2021, 5:50:17 PM