I have try like this.
You can extend or edit application/model/grocery_crud_model.php
Find function get_relation_n_n_unselected_array (at line +/- 349)
Replace with this one:
<?php
function get_relation_n_n_unselected_array($field_info, $selected_values)
{
$use_where_clause = !empty($field_info->where_clause);
$select = "";
$related_field_title = $field_info->title_field_selection_table;
$use_template = strpos($related_field_title,'{') !== false;
$field_name_hash = $this->_unique_field_name($related_field_title);
if($use_template)
{
$related_field_title = str_replace(" ", " ", $related_field_title);
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
}
else
{
$select .= "$related_field_title as $field_name_hash";
}
$this->db->select('*, '.$select,false);
if($use_where_clause){
$this->db->where($field_info->where_clause);
}
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
// jinbatsu edit: sort order for using template {field_name}
if(!$use_template) {
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
} else {
preg_match_all('/\{([A-Za-z0-9_]+?)\}/', $field_info->title_field_selection_table, $out);
$field_title_sort_order_arr = $out['1'];
foreach ($field_title_sort_order_arr as $field_title_sort_order ) {
//$field_title_sort_order = str_replace(array('{','}'), '', $field_title_sort_order);
$this->db->order_by("{$field_info->selection_table}.{$field_title_sort_order}");
}
// $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
}
$results = $this->db->get($field_info->selection_table)->result();
$results_array = array();
foreach($results as $row)
{
if(!isset($selected_values[$row->$selection_primary_key]))
$results_array[$row->$selection_primary_key] = $row->{$field_name_hash};
}
return $results_array;
}
?>
This will use sort order by using template, like this example:
$crud->set_relation_n_n('disha', 'order_disha', 'disha', 'order_id', 'disha_id', '{disha_id} {disha_name}','priority');
will generate:
order_by('disha_id')
order_by('disha_name')