Displaying search field with omines/datatables-bundle - doctrine-orm

Im new to omines/datatables-bundle and I have problem displaying search.
I was studying documentation and was not able to get it working.
Ive created a table like this
$table = $dataTable->create()
->add('street', TextColumn::class, ["label" => "Street", "searchable" => true, "globalSearchable" => true])
->add('houseNumber', TextColumn::class, ["label" => "House number", "searchable" => true])
->add('postal', TextColumn::class, ["label" => "Postal Code", "searchable" => true])
->add('city', TextColumn::class, ["label" => "City", "searchable" => true])
->add('country', TextColumn::class, ["label" => "Country", "searchable" => true])
->createAdapter(ORMAdapter::class, [
'entity' => CustomAddress::class,
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('sales_request/add_custom_address.html.twig', ['datatable' => $table]);
Also, in my twig template
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true });
});
</script>
The datatable works fine, sorting is working etc, but I dont see the search input field.How should I configure it to display it?

For anyone finding this issue by searching - it's actually a configuration issue we didn't document well enough.
The default Symfony recipe sets the DataTables native dom option to a sane default, but it omits the search field as it's not universally required. In general one should configure the dom value correctly for the intended result.
For more information see https://github.com/omines/datatables-bundle/issues/57#issuecomment-453529328

You can just add option dom : 'Bfrtip'
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true, dom: 'Bfrtip' });
});
</script>

Related

Yii2 ActiveForm custom template for checkbox field

I'm looking to use a template for my checkboxList.
That's the properties i want to apply
class="switch" checked data-on-text="ON" data-off-text="OFF" data-on-color="teal"
<?php $form = ActiveForm::begin(); ?>
<ul class="list-unstyled">
<li>
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(ArrayHelper::map(Permission::find()->all(),'id', 'code')) ?>
</li><br>
</ul>
<div class="form-group">
<?= Html::submitButton($modelUserPermission->isNewRecord ? 'Create' : 'Update', ['class' => $modelUserPermission->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'value'=>'Create', 'name'=>'submit']) ?>
</div>
<?php ActiveForm::end(); ?>
<?= $form->field($model, 'recomended_by_user', ['template'=>'<div class="control-group">
<label class="control control--checkbox checkbox-small-text">Recomended by user
{input}
<div class="control__indicator"></div>
</label>
</div>'])->textInput(['class'=>"",'type'=>'checkbox'])?>
Use like this for custom Checkbox template
Answer provided by Bizley is correct, but here is one more alternate way you can try if you want.
<?php
$items_array = ArrayHelper::map(Permission::find()->all(),'id', 'code');
echo $form->field($model, 'id_permission')->checkboxList($items_array, [
'items' =>
function ($index, $label, $name, $checked, $value) {
return Html::checkbox($name, $checked, [
'value' => $value,
'label' => '<label for="' . $label . '">' . $label . '</label>',
'labelOptions' => [
// you can set label options here ],
],
]);
}, 'itemOptions' => ['class' => 'switch',
'data-on-text' => 'ON', 'data-off-text' => 'OFF', 'data-on-color' => 'teal'],
'separator' => false,]);
?>
If you want these properties in every checkbox (like Insane Skull asked) use itemOptions option.
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(
ArrayHelper::map(Permission::find()->all(),'id', 'code'),
[
'itemOptions' => [
'class' => 'switch',
'data' => [
'on-text' => 'ON',
'off-text' => 'OFF',
'on-color' => 'teal'
],
],
]
) ?>
Since it's ActiveField widget in order to get all checkboxes checked you have to pass array to $modelUserPermission->id_permission with all the IDs.

Kendo UI External Editing Form

I'm Working on a project in which i have implemented Kendo Grid and when i click the edit button a popup for editing is displayed. But what i want is a separate panel alongside of kendo grid which i have made using [bootstrap][1] and i want to populate it with the editing detail of particular row clicked in the Kendo grid. I have attached the image below to give you an idea what i want. the help bordered area is where i want to populate it showing editable detail of selected row. Any Help??
#(Html.Kendo().Grid<UserItem>()
.Name("usergrid")
.HtmlAttributes(new { style = "width:100%" })
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.EmailAddress);
columns.ForeignKey(o => o.RoleId, (System.Collections.IEnumerable)ViewData["Roles"], "Id", "Description")
.Title("Role");
columns.ForeignKey(o => o.SystemRoleId, (System.Collections.IEnumerable)ViewData["SystemRoles"], "Id", "Description")
.Title("Sys Role");
columns.ForeignKey(o => o.TimeZoneId, (System.Collections.IEnumerable)ViewData["TimeZones"], "Id", "Description")
.Title("Time Zone");
columns.Bound(e => e.DefaultPageSize).Title("Default Page Size");
columns.Bound(o => o.IsActive).Title("Is Active");
columns.Bound(o => o.LastLoginDate).Format("{0:d}").Title("Last Login");
columns.Command(command => { command.Edit().Text("Edit"); });
})
.ToolBar(toolbar =>
{
toolbar.Template(#<text>
<div class="toolbar">
<span id="divCompany" style='#(roleName == Constants.SystemRoles.FifthMethod?"":"display:none;")'>
<label class="category-label" for="ddlCompany">Companies :</label>
#(Html.Kendo().DropDownList()
.Name("ddlCompany")
.DataTextField("Name")
.DataValueField("Id")
.AutoBind(true)
.Events(e => e.Change("CompanyChange"))
.HtmlAttributes(new { style = "width: 150px;" })
.BindTo(ViewBag.Companies)
.Value(Convert.ToString(ViewBag.CurrentCompanyID))
)
</span>
#Html.Kendo().Button().Name("btnNewUser").Content("New User").HtmlAttributes(new { #class = "k-button k-button-icontext k-grid-add pull-right" })
<button type="button" data-toggle="modal" data-target="#importUser-pop" class="k-button k-button-icontext pull-right">Import Users</button>
</div>
</text>);
})
.Editable(editable =>
{
editable.Mode(GridEditMode.PopUp);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(c => c.UserId);
model.Field(c => c.LastLoginDate).Editable(false);
})
.Create(create => create.Action("User_Create", "User").Data("GetCompanyId"))
.Read(read => read.Action("User_Read", "User").Data("GetCompanyId"))
.Update(update => update.Action("User_Update", "User"))
)
.Pageable()
.Sortable()
.Filterable()
.Events(e => e.Edit("grid_Edit"))
)
A complete example already exists in Kendo Docs how to edit records using external forms
A mvvm bounded section <div id="editForm"> to grid row using kendo.bind($("#editForm"), viewModel)

Emberjs Binding stop working when select multipe = true

If the select is multipe=false, it works. If we change it to multiple=true, the bindings stop working.
http://jsfiddle.net/6Evrq/163/
App = Ember.Application.create();
App.Router.map(function () {
// put your routes here
});
App.IndexController = Ember.ObjectController.extend({
selectedServiceFlavours: Ember.computed.defaultTo('serviceFlavours.firstObject.myvalue'),
serviceFlavours: function(){
return [
{name: "1 (1)", myvalue: "1"},
{name: "2 (2)", myvalue: "2"},
{name: "3 (3)", myvalue: "3"}
];
}.property(),
});
And the select:
{{view Ember.Select content=serviceFlavours optionLabelPath="content.name" optionValuePath="content.myvalue" value=selectedServiceFlavours multiple=true }} selected: {{selectedServiceFlavours}}
Since the value property is not supported for a multiple select, you must use the selection property as you did in your fiddle:
{{view Ember.Select content=serviceFlavours optionLabelPath="content.name"
optionValuePath="content.myvalue" selection=selectedServiceFlavours multiple=true}}
In order to get your selected option to return to default on content update you need to pass the correct parameter to your computed property, like this:
selectedServiceFlavours: function () {
return [this.get('serviceFlavours.firstObject')];
}.property('serviceFlavours')
This way Ember knows to update the selectedServiceFlavour when the serviceFlavours change.
Here is your updated fiddle: http://jsfiddle.net/taLgt1md/5/

ember render w/ ArrayController

I am trying to get a menu working using {{render}} in ember.
Controller:
App.NavigationController = Ember.ArrayController.extend({
itemController: 'navSheet',
init: function() {
this._super();
this.set( 'content', [
{ name: 'Sheet 1', type: 'Sheet', id: 1 },
{ name: 'Sheet 2', type: 'Sheet', id: 2 }
]);
}
});
App.NavSheetController = Ember.ObjectController.extend({
getID: function() {
return 'sheet-' + this.get( 'id' );
}
});
Then I use {{render "navigation"}} to render using the following emblem template:
ul
each controller.content
li data-type=type! id=getID! = name
[UPDATE WITH OUTPUT]
With "controller.content" here, I do loop through the content. With use "each" this isn't available. However, in any case the itemController is not in the context inside the loop. The resulting HTML is:
<li data-type="Sheet" id="">
<script id="metamorph-8-start" type="text/x-placeholder"></script>Sheet 1
<script id="metamorph-8-end" type="text/x-placeholder"></script></li>
<li data-type="Sheet" id="">
<script id="metamorph-9-start" type="text/x-placeholder"></script>Sheet 2
<script id="metamorph-9-end" type="text/x-placeholder"></script></li>
Note in particular that "getID" value doesn't show up. In fact I can't seem to access the itemController at all. What am I doing wrong?
I've never used a emblem, so I don't totally understand the template, but if I understand correctly you're trying to get sheetId into the li and you're using the getID function to do this. I'm going to guess that Emblem will convert it into this template
<li {{bind-attr data-type=type dataid=getID}}>
But it also looks like you're doing getID!=name or something like that. That kind of logic wouldn't work in handlebars.
Now getID won't run because it needs to be a computed property
App.NavSheetController = Ember.ObjectController.extend({
getID: function() {
return 'sheet-' + this.get( 'id' );
}.property('id')
});

How do I create a component that generates Radio-buttons in Ember.js?

Can I and should i pass arrays to components in ember?
For example if I wanted to template something that renders a couple of radiobuttons with labels:
<label for="media">Media</label><input type="radio" name="entry.1602323871" value="media" id="media" />
<label for="guest">Guest</label><input type="radio" name="entry.1602323871" value="guest" id="guest" />
Could I somehow pass an array with this content and loop through it.
Media, media
Guest, guest
Yeah, You can pass anything to components. Just a try to the radio-buttons
//Basic radio Component
App.RadioButton = Ember.Component.extend({
tagName : "input",
type : "radio",
attributeBindings : [ "name", "type", "value", "checked:checked" ],
click : function() {
this.set("selection", this.$().val());
},
checked : function() {
return this.get("value") === this.get("selection");
}.property('selection')
});
Em.Handlebars.helper('radio-button',App.RadioButton);
Updated (component name should be dasherized)
Working Radio Demo
It's now a tiny bit easier to get radio-buttons into your project (if you're using ember-cli) by using the ember-radio-buttons addon
Install:
npm install ember-radio-buttons --save-dev
Usage:
{{radio-button value='one' checked=selectedNumber}}
{{radio-button value='two' checked=selectedNumber}}
Upped #selva-G's answer.
I found that using the ButtonGroup Component from Bootstrap-for-Ember is actually cleaner.
Here's what I've done:
In my view's template:
<script type="text/x-handlebars" data-template-name="myview">
{{bs-btn-group contentBinding="things" selectedBinding="selectedThing"}}
</script>
In that view's controller (which doesn't necessarily need to be an ArrayController, rather can be a generic Ember Controller):
App.MyviewController = Ember.ArrayController.extend({
things: [
Ember.Object.create({value: 'first', title: 'First Thing'}),
Ember.Object.create({value: 'second', title: 'Second Thing'}),
Ember.Object.create({value: 'third', title: 'Third Thing'})
],
selectedThing: 'second'
selection: function() {
console.log(this.get('selectedThing');
}.observes('selectedThing')
});