How to show first preserve_default_filters! and after custom filter - activeadmin

I have this in my code:
preserve_default_filters!
filter :oculto,
as: :check_boxes,
collection: [['Oculto', true], ['visible', false]],
label: 'Mostrar'
I want to show default filters first and show after my custom filter, but I don't know how.
I attached a sample of my index page, how it shows it and how I want it

This is not supported out of the box but reading through the code I found https://github.com/activeadmin/activeadmin/blob/1290efa1fc7984badebe774f108d886a1e82624c/lib/active_admin/filters/resource_extension.rb#L93..L97 which led me to replace preserve_default_filters! above with:
config.send(:default_filters).each { |f| filter f }
filter :oculto ...
This takes the default filters and inserts them before yours. It might be interesting to submit a pull request adding this to lib/activeadmin/filters/dsl.rb:
def default_filters
config.send(:default_filters).each { |f| filter f }
end
Then you would be able to register the resource with:
default_filters
filter :oculto ...

Related

Is it possible to do a Lookup use Kiba

Is it possible to do a "Lookup" with Kiba.
Since it's quite a normal process in a etl.
Could you show a demo if yes, thanks.
Yes, a lookup can be done with Kiba!
For a tutorial, see this live coding session I recorded, I create a lookup transform to lookup extra fields using a given fields by tapping in the MovieDB database.
Leveraging this example, you could for instance implement a simple ActiveRecord lookup using a block transform:
# assuming you have a 'country_iso_2' field in the row above
transform do |row|
country = Country.where(iso_2: row['country_iso_2']).first
row['country_name'] = country.try(:name) || 'Unknown'
row
end
or you could extract a more reusable class transform that you would call like this:
transform ActiveRecordLookup, model: Country,
lookup_on: 'country_iso_2',
fetch_fields: { 'name' => 'country_name' }
transform DefaultValue, 'name' => 'Unknown'
Obviously, if you have the need for large volumes, you will have to implement some improvements (e.g. caching, bulk reading).
Hope this helps!

jQuery, activeadmin: custom filter with ransack. how to alter displayed text in search box

i got activeadmin (1.0.0.pre1) working with rails-jquery-autocomplete (1.0.2) [rails-4 setup].
i am able to auto-complete queries and call a search on them; however, when the search returns and the index form reloads, the search box (in sidebar panel) displays queried string wrapped in ["string"] (square braces and quotes)
e.g. if i search with AWonderfulDay and select an auto-completed element, the form reload results in ["AWonderfulDay"] shown as innerText of input element (search box)
Following is the generated UI element
<input data-autocomplete="/comments/autocomplete_comments" id="q_comments_in" name="q[comments_in]" type="text" value="["SearchString"]" class="ui-autocomplete-input" autocomplete="off">
The search has been implemented using ransack and the filter is:
filter :comments_in, as: :autocomplete, url: '/comments/autocomplete_comments',
label: 'Search Comments', required: false,
wrapper_html: {style: "list-style: none"}
pointed to a trivial:
ransacker :comment,
:formatter => ->(comment) {
data = User.joins(:profile => :comment).where("comments.comment = ?", comment).map(&:id)
data = data.present? ? data: nil
} do |parent|
parent.table[:id]
end
i do know this is because of in predicate (doesn't happen with cont predicate and i have that in another filter working well, e.g. filter :comments_cont will not cause this)
edit 1:
Also, https://github.com/activerecord-hackery/ransack/issues/345 shows a snapshot with same behavior.
This also led me to another question here Custom search with ransacker
i should have done a better job at looking up for them earlier. sorry for that!
edit 2:
here are my model relations:
class User < ActiveRecord::Base
belongs_to :profile, :inverse_of => :users, :touch => true
class Profile < ActiveRecord::Base
has_one :comment, dependent: :destroy
class Comment < ActiveRecord::Base
belongs_to :profile, touch: true
i solved it by correcting my use of ransack.
In models/comment.rb:
scope :search_comment, lambda { |x| ..}
def self.ransackable_scopes(auth_object = nil)
[:search_comment]
end
In admin/profile.rb
filter :search_comment, as: :autocomplete, url: "controller_url",
label: 'Search Comment', required: false,
wrapper_html: {style: 'list-style: none'}

Telerik MVC Grid Filter

I was using Telerik MVC Grid in my project. I just wanted to change the dropdown value orders a bit. I googled for the requirement and found the filter dropdown options are handled by **telerik.grid.min.js file. But, I dont know how can i change the order from
Options by Default
Is Equal to
Is not equal to
Starts with
Contains
Does not contain
Ends with
Change to the below format
Contains
Does not contain
Starts with
Ends with
Is Equal to
Is not equal to
Can anybody tell me the possibilities that i can change the order of filter dropdown box ..
Thanks,
You can do it by JQuery simply by some codes like this :
$('#GRIDID').find(".t-filter").click(function () {
setTimeout(function () {
$(".t-filter-operator").html('<option value="substringof">Contains</option><option value="notsubstringof">Does not contain</option>');
});
});
NOTE : the above code is a sample, you should do a process to check what operators you have and then repopulate the items in desired order. You can find all allowed "option" tags by inspecting the rendered grid.
The easy way (if you're using MVC razor syntax)
#Html.Kendo().Grid<Model>().Columns(columns =>
{
columns.Bound(x => x.variableName);
})
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains").DoesNotContain("DoesNotContain").WhateverYouNeed)
.ForEnums( dat => dat.Clear()
.IsEqualTo("Is Equal To"))
))
Here, the Clear() empties the options in the filter and then you can add the ones you want or even create your own custom ones there, simply place them there in the order that you want.
Have fun!

jqGrid filtertoolbar not firing after grid resizing

I have fixed row numbers to 10 for my subgrids, but if reccount is less than 10 I would want to adjust height subgrid to "auto" or "100%".
So here is my code for this subgrid :
// SUBGRID FOURTH LEVEL
var subgrid_table_id = subgrid_id+"_d",
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).append("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
$("#"+subgrid_table_id).jqGrid({
url:"sg31b.php?id="+row_id+"&clt="+clt,
datatype: "json",
idPrefix:"sgd_",
colNames: ['Id','Article','Désignation','Marque','Equivalence'],
colModel: [
{name:'e.id',index:'e.id',hidden:true},
{name:'a.code',index:'a.code', width:100},
{name:'a.descr',index:'a.descr', width:450},
{name:'k.code',index:'k.code', width:80},
{name:'e.equiv',index:'e.equiv',width:100}
],
pager: pager_id,
sortname: 'a.code',
hiddengrid:true,
scroll:true,
height:230,
rowNum:10,
autowidth:true,
caption:'4 - EQUIVALENCE ARTICLES',
gridComplete:function(){
sortDataCol(this);
if($("#"+subgrid_id+"_d").jqGrid('getGridParam','records') < $("#"+subgrid_id+"_d").jqGrid('getGridParam','rowNum')){
$("#"+subgrid_id+"_d").jqGrid('setGridHeight','100%');
}else{
$("#"+subgrid_id+"_d").jqGrid('setGridParam',[{npage:1}]).jqGrid('setGridHeight',230);
}
}
});
$("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{search:false,add:false,edit:false,del:false});
$("#"+subgrid_table_id).jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
fullInputCss();
and the snapshot of result for less than 10 filtered rows :
Now if I press Backspace in search field to obtain more rows, it seems that search doesn't fire because Firebug doesn't show any trace of request :
If I delete added 'setGridHeight' lines in gridcomplete, all runs fine !
I think that one more time I'm wrong in my coding and understanding how jqGrid runs.
Please could someone give me some way to solve this trouble ?
Many thanks in advance. Have a nice day. JiheL
I suppose that the origin of the problem could be id duplicates on your page. Just now I wrote the answer on another your question where I described the problem detailed.
Current implementation of jqGrid (version 4.4.5) has problem in the code of filterToolbar which constructs id for input fields of the filter toolbar based on the following rule:
id="gs_" + cm.name
(see the line of code). It means that the id of the input field for the column a.code will be gs_a.code for every subgrid which you use. So you can have id duplicates.
So I recommend you redesign the naming concept in your code. You can use for example
name: row_id + "a_code", index: "a.code"
In the way the value like "a.code" will be still send during sorting of the grid, but you will have no id duplicates. In some scenarios (is you use repeatitems: false in jsonReader) you could need to use additional jsonmap attribute, but you don't need it in you current code.

Grails: How do I create filter like the ones in MS Excel?

I want to sort the elements in my list and have the option of filter them the same way MS Excel does.
So it should be able to keep the filtered elements in the table and apply a filter within those results as well. Also be able to sort them without refreshing the whole table.
Any help is greatly appreciated!
you can do it with a criteria in you list action of your controller
def result
if ( params?.filter && params?.filterVal) {
result = Book.createCriteria().list(max: params?.max, offset: params?.offset) {
eq(params?.filter,params?.filterVal)
}
} else {
// normal list retrieval code
}
where params?.filter is the property to filter on and params?.filterVal is the value

Resources