[ 6 posts ]

jamatokwu

  • Joined: Tue May 25, 2010 10:31 am
  • Posts: 27
  • Offline
  • Profile

Datatable doesn't filter after autocomplete entry

Post Posted: Mon Jun 14, 2010 4:20 pm
+0-
Hello,

I'm trying to add AutoComplete to a datatable in order to filter the pertinent rows following the example here:

http://developer.yahoo.com/yui/examples ... plete.html

AutoComplete seems to work fine except the datatable doesn't refresh unless I click on a column header. When I try to sort a column it does so with the filtered datatable (but not before then). Also, the pagination values disappear. I know that autocomplete generates a new datatable because the sort column arrow disappears after the first character is entered. The pagination values disappear, too. Any thoughts on what I'm doing wrong?

Here is the HTML where the datatable is displayed:

<div class="yui-skin-sam">
<div id="myAutoComplete">
Find: <input id="myInput" type="text">
<div id="myContainer"></div>
</div>

<div id="dynamicdata" style="width: 100%"></div>
<div id="my_pagination" style="float: left"></div>
</div>


Here is the YUI / Javascript:

var rootFolder = '/bluerockny/';

YAHOO.DynamicData = function() {
var xmlDataSource = null,
myDataTable = null;

// Custom parser
var stringToDate = function(sData) {
var rgExp = /([0-9]{4})-([0-9]{2})-([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2})/;
var array = sData.match(rgExp);

if (sData) {
return new Date(array[1], array[2]-1, array[3], array[4], array[5], array[6]);
} else {
return;
}
};

var formatClientUrl = function(elCell, oRecord, oColumn, sData) {
elCell.innerHTML = "<a href='details.php?id=" + oRecord.getData("clientID") + "'>" + sData + "</a>";
};

var formatEditUrl = function(elCell, oRecord, oColumn, sData) {
elCell.innerHTML = "<a href='edit.php?id=" + oRecord.getData("clientID") + "'>Edit</a>";
};

var getTerms = function(query) {
xmlDataSource.sendRequest( 'name=' + query, myDataTable.onDataReturnInitializeTable, myDataTable );
};

var oACDS = new YAHOO.util.FunctionDataSource(getTerms);
oACDS.queryMatchContains = true;
var oAutoComp = new YAHOO.widget.AutoComplete( "myInput", "myContainer", oACDS );

// Column definitions
var myColumnDefs = [ // sortable:true enables sorting
{key:"clientID", label:"Edit", sortable:false, formatter:formatEditUrl},
{key:"Name", label:"Client", sortable:true, formatter:formatClientUrl},
{key:"clientFolder", label:"Folder Name", sortable:true},
{key:"numJobs", label:"# of Jobs", sortable:true},
{key:"numPostings", label:"# of Postings", sortable:true},
{key:"LastLogin", label:"Last Login", sortable:true, formatter:"date"}
];

// DataSource instance
xmlDataSource = new YAHOO.util.DataSource( rootFolder + "ajaxScripts/clientsXML.filter.php?" );

// Set the responseType
xmlDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
xmlDataSource.useXPath = true;
xmlDataSource.connMethodPost = false;
xmlDataSource.connXhrMode = "queueRequests";
xmlDataSource.responseSchema = {
resultNode: "client",
fields: [
{key: "clientID", parser:"number"},
{key: "Name"},
{key: "userID", parser:"number"},
{key: "clientFolder"},
{key: "isActive"},
{key: "numJobs", parser:"number"},
{key: "numPostings", parser:"number"},
{key: "LastLogin", parser:stringToDate}
],
metaFields: {
totalRecords: "/clients/@totalRecords" // Access to value in the server response
}
};

// DataTable configuration
var myConfigs = {
initialRequest: "", // Initial request for first page of data

sortedBy : {key:"Name", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow

paginator : new YAHOO.widget.Paginator({
rowsPerPage: 25, // REQUIRED

// use an existing container element
containers: 'my_pagination',

// use a custom layout for pagination controls
template: "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}",

// show all links
pageLinks: YAHOO.widget.Paginator.VALUE_UNLIMITED,

// use these in the rows-per-page dropdown
rowsPerPageOptions: [25, 50, 100],
})
};

// DataTable instance
myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, xmlDataSource, myConfigs);

// Update totalRecords on the fly with value from server
myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}

return {
ds: xmlDataSource,
dt: myDataTable
};

}();

jamatokwu

  • Joined: Tue May 25, 2010 10:31 am
  • Posts: 27
  • Offline
  • Profile

Re: Datatable doesn't filter after autocomplete entry

Post Posted: Thu Jun 17, 2010 11:21 am
+0-
Any suggestions? The main issue is that the datatable is not being refreshed with autocomplete results. When I click on a sortable header the datatable refreshes properly.

tobytiger123

  • Joined: Wed Mar 24, 2010 12:55 am
  • Posts: 4
  • Offline
  • Profile

Re: Datatable doesn't filter after autocomplete entry

Post Posted: Wed Aug 25, 2010 11:57 pm
+0-
I'm having the exact same problem. Did you manage to get the problem sorted?

jamatokwu

  • Joined: Tue May 25, 2010 10:31 am
  • Posts: 27
  • Offline
  • Profile

Re: Datatable doesn't filter after autocomplete entry

Post Posted: Tue Nov 02, 2010 6:34 am
+0-
Sorry for the late reply, but I never found / received a solution to this problem.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Datatable doesn't filter after autocomplete entry

Post Posted: Tue Nov 02, 2010 7:43 am
+0-
Large chunks of code are discouraged in this forum not only because it takes space and it comes badly formatted, but it also discourages reading and analyzing. I honestly don't have much time to go extracting from your code, which has lost all indentation, the relevant pieces, so I don't.

jamatokwu

  • Joined: Tue May 25, 2010 10:31 am
  • Posts: 27
  • Offline
  • Profile

Re: Datatable doesn't filter after autocomplete entry

Post Posted: Tue Nov 02, 2010 8:18 am
+0-
Thank you for the notice, Satyam. I was only replying because I had not responded to tobytiger123's question.

Plus, I thought that providing the complete code would help identify where I was going wrong. Overall, I received no response whatsoever ... until now.
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum