Thanks for your patient!
BUT i am confused where should I put the submit_sort?
Creat a new js file? or PUT them in the index.thtml?
I was created a new function in my controlloer called submit_sort( ),
and paste your code. It was wrongl
THanks.
Asking so silly question.
f. wrote:
> Hi,
>
> > Should I creat a field called order in my, such as topics table?
> >
>
> Yes, you should.
> What worked for me:
>
>
> In my view, I have a div with the sortable items:
> <div id="sortlist">
> <?php foreach ($data as $data): ?>
> <div id="artdiv_<?php echo $data['Article']['id']; ?>"
> class="sortablediv">
> <p>whatever...</p>
> </div>
> <?php endforeach; ?>
> </div>
>
> I create the sortable js-code with
>
> <?php echo $ajax->sortable('sortlist', array(
> 'tag' => 'div',
> 'onUpdate' =>
> 'submit_sort'
> )); ?>
> You need to define the function to submit the data:
> <script type="text/javascript" charset="utf-8">
> function submit_sort() {
> var u = new Ajax.Updater('col4', /* i update a div with the
> results,,, */
> '<?php echo
> $html->url('/admin/articles/sort/'.$catid).'?' ?>' +
> Sortable.serialize('sortlist'),
> {
>
> onLoading:function(request){$('indicator').show()},
>
> onLoaded:function(request){$('indicator').hide()},
> asynchronous:true,
> evalScripts:true,
> requestHeaders:['X-Update', 'col4']
> }, false);
> }
> </script>
> the important part is to append the serialized list to the URL.
> Later in your controller you can access the data with
> $this->params['url']['sortlist']:
> if (!empty($this->params['url']['sortlist'])) {
> for ( $i=0; $i < count($this->params['url']['sortlist']);
> $i++ )
> {
> $this->Article->id =
> $this->params['url']['sortlist'][$i];
> $this->Article->saveField('sort', $i);
> }
> }
>
> hope this helped,
>
> f.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---