Hello friends I found the answer with some help from October CMS Help/Support
http://octobercms.com/index.php/forum/post/dropdown-shows-its-value-than-key-name-in-list-controller
and referred few concepts of laravel.
Model Class Method
public static function getSampleOptions()
{
return[
'1'=>'Mobile App',
'2'=>'Web App'
];
}
Columns.Yaml file
sample:
label: Sample Column
type: dropdown
Again back in the model, declare the attributes object and include the filed name as key with empty value
public $attributes = ['sample'=>''];
Define the getfield_nameAttribute() function to set the associated value for the appropriate key in the column
public function getSampleAttribute()
{
$result = $this->attributes['sample'];
$options = $this->getSampleOptions();
foreach($options as $key=>$value)
{
if($key == $result)
{
return $value;
}
}
}
Updated
The solution to rectify the problem while editing the record is simple.
Create a partial and modify the fields. yaml
_sample_options.htm (partial) // file name should begin with_(underscore)
<?php
$fieldOptions = $model->getSampleOptions();
$sample = $model->attributes['sample'];
?>
<select id="<?= $field->getId() ?>" name="<?= $field->getName() ?>" class="form-control custom-select" <?= $field->getAttributes() ?>>
<?php foreach($fieldOptions as $key=>$label)
{
?>
<option value="<?= $key ?>" <?php echo ($sample == $key)?"selected":''; ?>><?= $label ?></option>
<?php
} ?>
</select>
Here the $model and $field are the partial variables that are used to access the intended model's methods and properties.
Documentation : https://octobercms.com/docs/backend/forms#field-partial
Fields.Yaml file
sample:
label: Sample Field
type: partial
path: $/october/demo/controllers/sample/_sample_options.htm //path where the partial is located in the controller view