Tuesday, 15 September 2015

yii extensions - Yii: Best Performance Benificial way to include JS/Ajax functions in CGridview -



yii extensions - Yii: Best Performance Benificial way to include JS/Ajax functions in CGridview -

yii newbie here have tried more 1 time figure out way include ajax/js function in easy clean way in cgridview, code

'click'=> "function (){ $.fn.yiigridview.update('news-grid', { type:'post', url:$(this).attr('href'), success:function(data) { $('#ajflash').html(data).fadein().animate({ opacity: 1.0 }, 3000).fadeout('slow'); $.fn.yiigridview.update('news-grid'); } }) homecoming false;

}"

in opinion, whats cleanest, performance benificial way include this? give thanks time !!!

i don't know dont see necesary forcefulness grid update twice on single operation, don't include javascript that. depending on need there several approaches, sake of reply sick show easiest one:

create global object, in separate file:

//app.js var app = { updatesomething: function () { $.post( $(this).attr('href'), success:function(data) { $('#ajflash').html(data).fadein().animate({ opacity: 1.0 }, 3000).fadeout('slow'); $.fn.yiigridview.update('news-grid'); } ); homecoming false; } };

and can include file controller calling cclientscript::registerscriptfile

yii::app()->clientscript->registerscriptfile(yii::app()->baseurl."js/app.js");

and on grid:

'click'=> "js:app.updatesomething",

there much improve approaches, more simple js beginners want have kind of organization.

yii yii-extensions

No comments:

Post a Comment