yii2-multiple-input - Add and remove row in the middle - yii

I am working on a project and using yii2-multiple-input, but I would like to be able to add the row in the middle.
Do you know if this is something that we can do using yii2-multiple-input or do I have to try another approach?
Thanks!

There is a way to sort rows in multiple input:
$form->field($model, 'attribute')->widget(MultipleInput::className(), [
'sortable' => true
]);
After adding a new row in the last position, you can move it wherever you want.
For more information, check here.

Related

Yii2 Gridview get all selected row for all pagination

I wrapped my gridview with Pjax widget like this
\yii\widgets\Pjax::begin();
gridview
\yii\widgets\Pjax::end();
in order to make the gridview make ajax request when I click on each pagination.
I also use ['class' => 'yii\grid\CheckboxColumn'], in column as well.
and I find that when I'm on first pagination I checked some rows and then go to second page and check some rows but when I go back to first page what I've checked is gone.
My question is how can I keep all checkedrow for all pagination
With current conditions (Pjax, multiple pages, yii\grid\CheckboxColumn) it's impossible because of the way it works.
When you click on the pagination links all GridView html content is replaced by new one that comes from the AJAX response.
So obviously all selected checkboxes on the previous page are gone.
Few possible ways to solve that:
1) Write custom javascript and server side logic.
As one of the options, you can send AJAX request to server with parameter meaning that user has chosen to select all data for the bulk delete operation (or use separate controller action for bulk deletion). In this case actually we don't need to get the selected data from user, because we can simply get them from database (credits - Seng).
2) Increase number of displayed rows per page.
3) Use infinite scroll extension, for example this.
4) Break desired action in several iterations:
select needed rows on first page, do action (for example, delete).
repeat this again for other pages.
You can get selected rows like that:
$('#your-grid-view').yiiGridView('getSelectedRows');
[infinite scroll] : http://kop.github.io/yii2-scroll-pager/ will work good if you do not have any pjax filters. If you have filters also in play, do not use this plugin as it does not support pjax filters with it. For rest of the applications it is perfect to use.
Update1 : it seems to be straight forward than expected, here is the how I accomplished it
Add following lines to the checkbox column
'checkboxOptions' => function($data){
return ['id' => $data->id, 'onClick' => 'selectedRow(this)'];
}
Now add following JS to the common js file you will have in your project of the page where this datagrid resides
var selectedItems=[]; //global variable
/**
* Store the value of the selected row or delete it if it is unselected
*
* #param {checkbox} ele
*/
function selectedRow(ele){
if($(ele).is(':checked')) {
//push the element
if(!selectedItems.includes($(ele).attr('id'))) {
selectedItems.push($(ele).attr('id'));
}
} else {
//pop the element
if(selectedItems.includes($(ele).attr('id'))) {
selectedItems.pop($(ele).attr('id'));
}
}
}
Above function will store the selected row ids in the global variable array
Now add following lines to pjax:end event handler
$(document).on('pjax:end', function () {
//Select the already selected items on the grid view
if(!empty(selectedItems)){
$.each(selectedItems, function (index,value) {
$("#"+value).attr('checked',true);
});
}
});
Hope it helps.
I just solved this problem and it works properly with Pjax.
You may use my CheckboxColumn. I hope this can help. The checked items are recorded with cookies.
You can read the part with //add by hezll to understand how to fix it, because I didn't provide a complete general one.
Hope it works for you.
https://owncloud.xiwangkt.com/index.php/s/dGH3fezC5MGCx4H

how to make multiselect to singleselect in extjs?

Take a look at this example. Here you can see multiselect field that allows user to select multiple rows by pressing CTRL key down.
I have tried to use the keyUp function to capture the CTRL key, in order to somehow prevent user from selecting more than 1 row. But I am not sure hot to do this with mulitiselect xtype.
You might think way would I want a single select instead of multiselect, it is just something I need for my app I am working on. I like the layout of the example and want to keep the structure the same. The only thing I want to change is from multi -> single.
Thanks for any help.
The following config needs to go in your multiselect config. This will set the config for the boundList which is where the multiselect is.
listConfig: {
multiSelect: false
}

rails simple_form checkboxes reorder

I use
= f.association :some, as: :checkboxes
and got checkboxes like
But I need to reorder by alphabet and draw by columns
I try to reorder with js by counting columns, but faced with situation hen some labels stay near each other in one row, when label no enough long. Maybe js wrong idea and such task can solve by simple_form
= f.association :some, collection: Some.all(order: 'name'), as: :checkboxes
A side note - if you would actually use names that are not digits but are character based it should return then alphabetically by default.

Change the Row Color Based on the Column value in CGridView

In Yii, CGridView has it's own background color in the row. But what I want to do is highlight particular row based on the value of one of the column.
For Instance, I have three column, id, name, status. Now, If the Value of status is Inactive or 0, I should highlight the row with some color.
I read the class reference briefly and searched this site as well. But could not find the relevant solution. If some example or some direction toward the right solution, that would be much appreciated.
Thanks,
Ujjwal
CGridView 'rowCssClassExpression' is the way to get what you want.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'rowCssClassExpression'=>'($data->myFlag==0)?"normal":"especial"',
'columns'=>array(
...
),
));
You can also call a custom php function, and pass the $data variable to it. That function should return the class name for the given row :)
Use rowCssClass and rowCssClassExpression for your functionality. I did not tested this code but the trick you can use to get your solution.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'rowCssClass'=>array('odd','even'),
'rowCssClassExpression'=>($data->status==0)?even:odd,
'columns'=>array(
),
));

In Dojo how to add node to a tree in a sorted way?

In my Dojo application, I had a tree with nodes sorted by their name. Like this :
I already built a New form addition, and it can add a new node to this tree, but always at the bottom. Is there a way to insert this newly added node to the store in a correct sorted position? So if I am about to add 000-011 - Biaya Teknis Pengacara to this tree, it should be ended up this way :
To achieve this, currently I must refresh my browser. Surely, this is not what all user wanted.. :)
For the code addition of node itself, here it is:
//TOFIX : add in a sorted way
akunStore.newItem(
{"id":data.id.toString(),"name":data.name},
{"parent": groupsModel.root, "attribute":"groups"}
);
akunStore.save();
akunStore.fetch();
I add the fetch() as shown above, but it didn't work, currently.
Use the sort attribute in your call to the fetch() method of your data store. Try something like :
akunStore.fetch({
sort: [
{ attribute: "youFirstSortField" },
{ attribute: "aSecondSortField" }
]
});
You can also specify a descending order by adding "descending : true" in your sort params... more on that here : http://dojotoolkit.org/reference-guide/quickstart/data/usingdatastores/sorting.html#quickstart-data-usingdatastores-sorting