1

In Drupal 6, I am using tableselect theme with PagerSelect to generate table with checkboxes and pagination. Any thoughts on how to retain checkbox values on pagination? Because in the first page , i checked 2 checkbox and go to the second page and check other checkbox

When i go back to the first page , the checked checkbox are lost

How can i fix it ?

here is how i do this using a method that not follow the drupal standard coding like this

function mymodule_form(){
    global $base_url;
     drupal_add_js('misc/jquery.js', 'core', 'header');
     print drupal_get_js(); 
     $url = $base_url.'/'.arg(1);

        <script type="text/javascript">
            var chkArray = new Array;
            var someGlobalArray = new Array;
            var hrefs = [];
            var burl = "<?php echo $base_url.'/'.arg(1); ?>";
            $(document).ready(function(){
                    $('li.pager-item').find("a").each(function(){
                        hrefs.push($(this).attr('href'));
                    });

                    $(".form-checkbox").click(function() {
                        someGlobalArray=[];
                        $('.form-checkbox:checked').each(function() {
                            someGlobalArray.push($(this).val());
                        });
                        console.log(someGlobalArray);
                        i = 0;
                        $('li.pager-item').find("a").each(function(){
                            //h = $(this).attr('href');
                            h = hrefs[i] + "&ids[]=" + someGlobalArray.join(",");
                            $(this).attr('href', h);
                            //someGlobalArray = [];
                            i++;
                        });
                    });
            });
        </script>



     $form = array(); 
     $tableHeader = array(
        'test' => array('field' => 'n.title', 'data' => 'test'),
        'test1' => array('field' => 'l.name', 'data' => 'test1'),
        'test2' => array('field' => 'l.postal_code', 'data' => 'test2'),
        'test3' => array('field' => 'l.city', 'data' => 'test3'),
        'test4' => array('field' => 'cttc.field_activite_nid', 'data' => 'test4'),
        'test5' => array('field' => 'cttc.field_gestionnaire_value', 'data' => 'test5'),
     );
    $query = "SELECT nid FROM  table  ";
    // Pass the sql to the tablesort_sql here
    $query .= tablesort_sql($tableHeader);

   $result = pager_query($query,250,0,$sql_count);  

   while ($row =db_fetch_object($result)) {
         $nid_list[] = $row->nid;
   }

    foreach($nid_list as $val){
         $node = node_load($val);
         //print "<pre>";print_r($node);
         $options[$node->nid] = array(
             'test' => $node->title,
             'test1' => $node->location['street'],
             'test2' => $node->location['postal_code'],
             'test3' => $node->location['city'],
             'test4' => $tmp_activite[$node->field_activite[0]['nid']],
             'test4' => $node->field_gestionnaire[0]['value'],
         );
    }     
    if (!empty($options)) {
            $ids = isset($_GET["ids"]) ? $_GET["ids"] : array();
            $tab_check = array();
            global $tab_check;
            foreach($ids as $v) {
                //print_r($ids);
                $tids = explode(",", $v);
                foreach($tids as $id) {
                    $tab_check[$id] = TRUE;
                }
            }
            //print "<pre>";print_r($tab_check);
            if(arg(2)!=""){
                $form['nodes'] = array(
                  '#type' => 'tableselect',
                  '#header' => $tableHeader,
                  '#options' => $options,
                  '#default_value' => $tab_check,
                  '#multiple' => TRUE,
                  '#advanced_select' => TRUE,
                );
            }else{
                $form['nodes'] = array(
                  '#type' => 'tableselect',
                  '#header' => $tableHeader,
                  '#options' => $options,
                   '#default_value' => $tab_check,
                   '#multiple' => TRUE,
                  '#advanced_select' => TRUE,
                );
            }
            $form['pager'] = array('#value' => theme('pager', NULL, 250, 0));
    }
  return $form;
}

function mymodule_form_submit($form, &$form_state) {
     $ids_del = isset($_GET["ids"]) ? $_GET["ids"] : array();
            $tab_check_del = array();
            foreach($ids_del as $v) {
                $tids_del = explode(",", $v);
                foreach($tids_del as $id) {
                    $tab_check_del[] = $id;
                }
            } 

     if(sizeof(tab_check_del)>0){
      foreach($tab_check_del as $val){
        $query = "DELETE from mytable WHERE nid ='".$val."' ";
        db_query($query);
      }

}
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.