RecordGrid not sortable for a custom action

Archived from the Xataface Users forum.

Jean — Wed Jul 02, 2008 7:08 am

Hi Steve,

I send a good array for my grid. Here is the result I send to the grid through the object $this->records :

Code: Select all
Array (     [id] => tte83545     [annee] => 2007     [nom] => Le bois du roy     [commune] => idron     [maitre_ouvrage] => Sivom     [nombre_logements] => 318     [type_logements] => NEUF )

Then I have this warning

Code: Select all
Warning: array_keys(): The first argument should be an array in /var/www/html/xataface-1.0-beta-3/Dataface/RecordGrid.php on line 100

The line from where all this is caused by is

Code: Select all
$columns = array_keys($sampleRecord);

The warning is OK but I don’t understand the 2 lines preceding this error:

Code: Select all
$recKeys = array_keys($this->records);       $sampleRecord =& $this->records[$recKeys[0]];

These two lines force $sampleRecord to be a record and not a string.

I don’t see how to feed it with something else.

I hope I am clear enough.

Jean


shannah — Wed Jul 02, 2008 9:56 am

Hi Jean,

I The record grid requires you to pass it an array of either arrays, records, or related records. It looks like you have passed it only an array.

The lines you are referring to effectively peek at the first item in the array so that we can figure out the columns we need (the next section figures out the columns), whether the first item is an array or a record.

-Steve


Jean — Thu Jul 03, 2008 2:06 am

Thank you Steve. Well I understand the logics.

I succeeded to display the recordGrid but without any link in the column headings to sort by any column.

Did I miss something in the installation ? I just kept my app unchanged, just changed the url to the Xataface beta 3 although it had been built with the 0.7.1 version.
Is the fact that my data comes from several tables has any influence ?
Did I miss any line to include so that some javascript would be included in my column headings.

I search explanations in the forum but the recordgrid questions were often before the version 1 and I did not find any solution.

id is set on “sortable”.

Kind regards

Jean


Jean — Fri Jul 04, 2008 1:35 am

I use MySQL 4.1.18 so I cannot use any view. With the temporary tables, I cannot use Ajax. I look forward to use a xml file. Has anybody used this kind of solution ?

Thank you

Jean


shannah — Fri Jul 04, 2008 10:00 am

Hi Jean,

The record grid won’t give a link per-se for sorting. However if you click in the heading of a column it should sort on that column using javascript (as long as the id of the record grid (the id attribute of the <table> tag) is “sortable”.

I believe it will also work if the class is sortable.

If this is not the case, let me know, and I’ll take a closer look. Do you have a URL that I can check it out?

-Steve


Jean — Mon Jul 07, 2008 5:42 am

Thank you Steve, very kind of you. Unfortunately, I am working on an intranet.

I tried to have a class sortable without any change. But I noticed one or two things.

Please look at the normal grid from a table

The source page is >table id=”sortable” class=”listing “< …

Code: Select all
<thead>             <tr><th><input></th>   <th><Expand></th>             <th><a>Code de l'opération</a></th>

and all the javascript for each column.

Now with my custom action statistiques

The source page is >table id=”result_list” class=”listing”<…

Code: Select all
`<thead>

      <tr>
            <th>Id</th>
            <th>Annee</th>
            <th>Nom</th>
            <th>Commune</th>
            <th>Maitre Ouvrage</th>

            <th>Nombre Logements</th>
            <th>Type Logements</th>
            </tr>
   </thead>
   <tbody>
            <tr>
                  <td>000001</td>

                  <td>2008</td>
                  <td>Résidence</td>
                  <td>Pau</td>
                  <td>Habitat</td>
                  <td>65</td>
                  <td>NEUF</td>

               </tr>
         </tbody>
</table>`

I sent this data to the template in my action file

Code: Select all
`$info = array();
  while ( $rang = mysql_fetch_assoc($resultat) ) {

$info[]=$rang;
}

import(‘Dataface/SkinTool.php’);
import(‘Dataface/RecordGrid.php’);
$grid = new Dataface_RecordGrid(& $info);

df_display(array(‘body’=>$grid->toHtml()), ‘Dataface_Main_Template.html’);
exit;`

As you can see I don’t have te same display nor the same id… for the table in both cases.

Thank you Steve for your help

Jean


shannah — Mon Jul 07, 2008 10:05 am

Hi Jean,

Yes.. It doesn’t appear to be picking up the id sortable. It occurs to me that you also need to update your Dataface_RecordGrid.html template. If you copy the one from 1.0-beta-3 it should work.

You’ll know it is working when the table tag looks something like:

Code: Select all
<table id="sortable" ...>

-Steve


Jean — Tue Jul 08, 2008 1:52 am

Oups Steve.

I switched the two source codes. Where I have the table id=”sortable”, it is the second image and it does not work.

And my Dataface_RecordGrid.html is the right one, the one from the 1.0-beta-3.

I don’t know which track to follow. May be the template is a good hunch…

thank you

Jean


shannah — Tue Jul 08, 2008 7:51 am

Hi Jean,

The images don’t make it clear as the record grid doesn’t use a conventional link. However if you click on the column headers id should sort (and will show a little arrow indicating the direction of the sort).

Can you provide a URL for me to take a look?

-Steve


Jean — Tue Jul 08, 2008 11:19 pm

Sorry Steve, I am positive about the fact I don’t have any link in the colum headings. And unfortunately there is no web access on the intranet where the application is.

Thank you

Jean


shannah — Wed Jul 09, 2008 11:01 am

Sorry.. my mistake. You need to set the css class ‘listing2’ to get sorting ability.

Here is a sample action that creates a grid from an array, and is sortable:

Code: Select all
<php>'Steve', 'Age'=>24, 'Subject'=>'Math'),          array('Name'=>'Paul', 'Age'=>28, 'Subject'=>'Socials'),          array('Name'=>'Mary', 'Age'=>14, 'Subject'=>'Physics'),          array('Name'=>'John', 'Age'=>10, 'Subject'=>'Spelling')       );              $grid = new Dataface_RecordGrid($data);       $grid->cssclass = 'listing2';       df_display(array('body'=>$grid->toHtml()), 'Dataface_Main_Template.html');    } }

Jean — Wed Jul 09, 2008 11:29 pm

Thank you Steve it works! As great as your soft is, your availability and dedication are a great asset !

This line opens new perspectives for me

Code: Select all
$grid->cssclass = 'listing2';

Thank you

Jean


Jean — Thu Jul 10, 2008 12:57 am

one last question Steve on this topic :

*How can I load actions_menu_head block and actions_menu_tail to my page ?

Jean


shannah — Sun Jul 13, 2008 9:29 pm

*How can I load actions_menu_head block and actions_menu_tail to my page ?

Sorry. Missed this question on the first time around. I’m not sure I understand the question exactly. Can you elaborate on exactly what you want to show?

-Steve


Jean — Tue Jul 15, 2008 5:23 am

Thank you Steve,

I need to have the csv link like this :

in the result page of my action

Code: Select all
`$info = array();
  while ( $rang = mysql_fetch_assoc($resultat) ) {

$info[]=$rang;
}

import(‘Dataface/SkinTool.php’);
import(‘Dataface/RecordGrid.php’);
$grid = new Dataface_RecordGrid(& $info);

df_display(array(‘body’=>$grid->toHtml()), ‘Dataface_Main_Template.html’);
exit;`

Jean


shannah — Wed Jul 09, 2008 11:01 am

Sorry.. my mistake. You need to set the css class ‘listing2’ to get sorting ability.

Here is a sample action that creates a grid from an array, and is sortable:

Code: Select all
<php>'Steve', 'Age'=>24, 'Subject'=>'Math'),          array('Name'=>'Paul', 'Age'=>28, 'Subject'=>'Socials'),          array('Name'=>'Mary', 'Age'=>14, 'Subject'=>'Physics'),          array('Name'=>'John', 'Age'=>10, 'Subject'=>'Spelling')       );              $grid = new Dataface_RecordGrid($data);       $grid->cssclass = 'listing2';       df_display(array('body'=>$grid->toHtml()), 'Dataface_Main_Template.html');    } }

Jean — Wed Jul 09, 2008 11:29 pm

Thank you Steve it works! As great as your soft is, your availability and dedication are a great asset !

This line opens new perspectives for me

Code: Select all
$grid->cssclass = 'listing2';

Thank you

Jean


Jean — Thu Jul 10, 2008 12:57 am

one last question Steve on this topic :

*How can I load actions_menu_head block and actions_menu_tail to my page ?

Jean


shannah — Sun Jul 13, 2008 9:29 pm

*How can I load actions_menu_head block and actions_menu_tail to my page ?

Sorry. Missed this question on the first time around. I’m not sure I understand the question exactly. Can you elaborate on exactly what you want to show?

-Steve


Jean — Tue Jul 15, 2008 5:23 am

Thank you Steve,

I need to have the csv link like this :

in the result page of my action

Code: Select all
`$info = array();
  while ( $rang = mysql_fetch_assoc($resultat) ) {

$info[]=$rang;
}

import(‘Dataface/SkinTool.php’);
import(‘Dataface/RecordGrid.php’);
$grid = new Dataface_RecordGrid(& $info);

df_display(array(‘body’=>$grid->toHtml()), ‘Dataface_Main_Template.html’);
exit;`

Jean


shannah — Tue Jul 15, 2008 9:18 am

This is a bit tricky because the built-in CSV action in Xataface is designed to work within the context of the current found set. Since you are doing your own custom result set here (not influenced by the Xataface request variables) you won’t be able to use the default export CSV action.

However you can create your own custom action. Check out the actions/export_csv.php action for tips on how you might do it.

Then you can add your own button to your custom action.

-Steve


Jean — Tue Jul 15, 2008 11:23 pm

Thank you Steve, it works very well with the export_csv.php file untouched.

Jean