CListView with ajax - yii

I am new to Yii, I am trying to get a CListView to update using ajax instead of refreshing the page. To make the simplest example, I am just feeding the CListView with a dataprovider and giving it the itemView parameter, nothing else. I want the pagination to update the page without refreshing. It works with gii generated crud pages but will not work with mine. I have added nothing extra, the code for the gii generated example and my own should be the same. Is there some setup step I am missing? Is there javascript missing in my layout that the default layout has perhaps? Thank you in advance.

It turns out that I was loading jQuery in my layout which was interfering with the jQuery library automatically loaded in Yii. Simply removing my jQuery include solved the problem. I will chalk this one up to being new at Yii and not knowing the inner workings of how it automatically includes javascript. Thanks guys, Rajat you put my mind on the right track, thanks.

Related

Using ViewComponents in RTE

I am trying to use ViewComponents tag helpers in CKEditor to show some products but it doesn't.
I created a vc tag helper like this :
<vc:products html-class="col-12 col-md-5" html-style="" skip="0" take="10"></vc:products>
Now I am trying to use this code in CKEditor, I mean post editors can call products anywhere they want. but it doesn't work. CKEditor shows it as a html code.
what should I do?
This code will be actually executed on the server side and it will add partial html to your page then the server will return it to the client.
<vc:products html-class="col-12 col-md-5" html-style="" skip="0" take="10"></vc:products>
Here I'm not sure what you are trying to accomplish, but you cannot dynamically use tag helpers on the client side. May be this link can help you.
Dynamically Produce Razor Views at Runtime?

ASP.NET MVC 4 changing contents of div without reloading

I'm new to web development and ASP.NET MVC 4
My question is: Is it possible to replace the content of div tag without needing to refresh the whole page?
If so, what is the best practice of it (best use of MVC 4)?
In order to refresh partial content of a page, you have to use AJAX. There are plenty of resources available online describing how to implement this in ASP.NET MVC. One of the possibilities is using partial views, on which you can find a good tutorial here. However, if you're comfortable with javascript/jQuery a partial view might be overkill if you're just looking to update one div.
Use javascript and make an ajax call. MVC has a JsonResult for the controller you can use if you like.
Not 100% sure but if I remember right, jQuery is bundled with MVC4. Correct me if I'm wrong.
// Javascript code
$('#mydiv').load('/Content/html/mySnippet.html');
Would replace the contents of a <div id="mydiv"></div> with the contents of the /Content/html/mySnippet.html.
You can also call an action and return a partial view if you wish to have dynamic content instead of a static html template.

Jquery Form Validation NOT USING model Annotations

I have tried asking this question in a number of ways, and I still can't get an answer. In Asp.net MVC4, is there a way I can just add jquery code to my views and not have to add any kind of annotation to a model to validate my form input? I just realized that I am using Ajax.BeginForm... I am betting that I cannot using regular Jquery Ajax calls with that on my form. I bet if I use HTML.beginForm, regular jquery will work. But now that will break my ajax calls... Which were failing for some reason. Well, I am about to find out why. Hopefully I can figure out how to just avoid using all Asp.net Ajax crap. It has given me nothing but a massive headache. Oh wait, you know what, I just looked at another view, and there I am using Html.BeginForm and I still can't use plain jquery code in my views to validate my form. Is this even possible in MVC4?
of course this is possible - ASP.NET MVC just emits HTML yes? so just add some jquery validate code to the document ready.
$(function(){
$('#myform').validate(/* options here */);
});

Would like to add some custom ajax & javascript to activeadmin based application

Hi guys I'm working on this application using activeadmin. I've come to a point where I would like to add in some ajax based functions. I have the basic form set up using teh activeadmin resource and it generates a very pretty form.
I would like to while the user is entering the details on the form - run a ajax call which would retrieve some html based on the values being entered and populate it on the page.
More likely I would like a way to add custom javascript to the page. Whats the best way to do this - I'm facing issues with returning html without the entire activeadmin layout coming with it.
You can use the /config/initializers/active_admin.rb
You can add javascript resources like this:
config.register_javascript 'my_functions.js'
I use to put code directly to /app/assets/javascripts/active_admin.js
You can also include script in /config/initializers/active_admin.rb

Yii Bootstrap Extension Gridview

I have been using CGridView without any issues previously but when I use Bootstrap extension the filters stop working.
Moreover the Ajax requests for CButtonColumn are set to use POST but when I use BootButtonColumn it uses GET and ignores the fact that ajax type is set to POST
Any ideas on how to fix the problems.
I went back to using zii widgets but today looking at the documentation for a totally unrelated reason I came across this property "ajaxUpdate". Below is the excerpt from Yii documentation.
ajaxUpdate property
public mixed $ajaxUpdate;
the ID of the container whose content may be updated with an AJAX response. Defaults to null, meaning the container for this grid view instance. If it is set false, it means sorting and pagination will be performed in normal page requests instead of AJAX requests. If the sorting and pagination should trigger the update of multiple containers' content in AJAX fashion, these container IDs may be listed here (separated with comma).
I am no longer using that extension but I am posting it here so that it maybe helpful to someone else.