problem with 'datatable' jquery plugin and two table (ajax related) - jquery-plugins

i have two tabs that their content loads by ajax. both have a table in their content. i want to apply 'datatable' jquery plugin to both table. tables have the same id because they are create by a function.but their rows are different.
datatable plugin is applied to first tab table well but on the second one give this error:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster)."
i use "bDestroy":true in datatable plugin define.but in this way the plugin doesn't show in second table.
would you help me?

Your problem is that both tables have the same ID, which is invalid HTML. When you try to initialize the second Databable, your selector only finds the first table and tries to initialize Datatables on the first table again, which results in the error that you are getting.
You need to change your function to create each table with a unique ID and initialize each table by its respective ID.

Why not set the Datatables by a className rather than ID then it can apply to both of them?
When retrieving the data you can use something like $('.dataTableStyle').eq(1) to get information from the relevant one.

I'm using mvc3 and my problem was with initializing a dataTable in a view, then rendering a partial view with another dataTable. The issue was not in the id's of the 2 tables, but in the way the partial views get rendered in the framework. In my case, I had to move the script, or reference to the script, into the view that hosts the partial view. I had an issue similar to this using the Google Maps api.

try this code
$(document).ready(function() {
oTable = $('#DataTables_Table_0').dataTable({ //DataTables_Table_0 <-------table id
iVote: -1, //your field name
"bRetrieve":true
});
oTable.fnSort( [ [1,'desc'] ] );
});

use this in function event when you would change your table data
$('#tbl_resultates').dataTable().fnDestroy();
and add
"bRetrieve": true,
in
$('#tbl_resultates').dataTable({

Related

Readeonly property in kendo mvc project, and not work when sorting or filtering this column

I have two table in my database.
first has a id and description and second table has a id, description and first table key, i create a relation between this. after that i create a readonly property in models of second table and get the description of first table by query. i save 100 row of data in second table and 10000 in first table, and each 100 row of first table for one of the row of second table. now when i sort or filter my kendo grid on this column , this take a long time to load! i test this by a more data and see this is not work! i know this in controller whit out read only property but i want to say me a way to use readonly property!! please guide me.
Your question is a little vague but if I understand correctly, it seems you are having problems dealing with large datasets, you may want to look into using serverFiltering and serverSorting.
Not sure if you have implemented your grid through Razor (.cshtml) or client (.js) however these links should get you on the right track.
A few more tutorial links:
Razor
Javascript

Servicenow - Service Catalog Reference Field - Insert different column than the display value

Let me describe my problem:
I have a table for all my IT-Services. I reference to this table more than once, for different purposes. Most of the time I need to reference to the name of the service. That's why I keep the name as displayed value.
One Column of that table is a service_id (custom field) which is for example "Service_004". Now in a catalog request Item the User has to fill in the service_id in a reference field.
But since I have the name as displayed value, and I need it in other forms, I am unable to reference to the service_id.
Using the variable attributes field I managed to let the service be found using the autocomplete function. But in the reference field I still get the servicename. I know that I can change the display value in the dictionary, but this breaks other functions. So what I need is to change the display value just for one reference field.
Also I tried to create a new table called IT-Services2 with reference to my table IT-Services. Then I switched the display to true in the new table for my service_id, but this will even change it in the parent table.
Perhaps an onChange client script utilizing g_form.setLabelOf() ?
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setLabelOf
Maybe I'm not fully understanding your question...
I ran into this issue before, what you can do is create select box variable and use an on load client script to populate the list with the service_id(s) from the table you are referencing.
I would write a script include to pull the data from the table and call it from the client script via GlideAjax.

creating a form field populated by a relationship in Laravel 4

I am trying to build a form for a Happening. The Happening references a Places table by place_id.
e.g. happening "OktoberFest" has a place_id 123 which corresponds in table Places to München
These are the relationships declared in the models:
For model Place:
public function happenings()
{
return $this->hasMany('Happening');
}
For model Happening:
public function place()
{
return $this->belongsTo('Place');
}
model Happening has a place_id field linking it to Place.
I am also using {{Form::model($happening, array('route' => array('happenings.update', $happening->id)...}} as form opening
Problem 1: how to create a {{Form::text('......')}} that will be properly prefilled with München when editing the happening Oktoberfest ?
Problem 2: I was trying to get that field to work as an ajax autosuggest (i.e. starting to pull suggestions from the Places table as soon as 3 characters have been entered). I have checked a few implementations but they don't seem to mix correctly with Problem 1
To try and solve Problem 1, I have tried the solution here
Laravel 4 Form builder Custom Fields Macro
but I was unable to make it work.
Long question, it's my very first on stack overflow, please be patient :)
If a Happening is linked to Place via the column 'place_id' you have to supply an id to save in your model/table.
There are a couple of ways that I can think of:
make a list of availble Places in a radio of select, the name will be 'place_id', the value the id of the Place en something like title for the value.
instead of displaying radio's or a select a textfield with autocomplete is a great solution if you got a lot of places. I won't go into detail how to implement it but the general idea is to autocomplete the typed in placename and on selection of that place to put the id of that place in a hidden field named 'placed_id'
After saving the form save your model with the posted place_id
(and check that id if it's valid and existing, never trust user input )

How to show data in input field when select data at dropdown in Grocery Crud and Codeigniter

In Grocery Crud and Codeigniter , Basically i want to show data from one table(such as a_tbl) when select data or id_no(id_no will get from a_tbl) in dropdown then Name and current posting data will take in input field from table(such as a_tbl) , Then Designation, Dept and Section will take in input field from three different table (such as desg_tbl, dept_tbl, sect_tbl).
How can i solve it , Please any help me
You can use AJAX.
If you use jquery, you can do something like:
$("#field-ID_No").change(function(){
$.ajax({
'url':'your_controller/get_name_of_id/'+$("#field-ID_No").val(),
'success':function(response){
$("#field-Name").value(response);
}
});
});
Basically, when field-ID_No (the select/combobox) changed, the program will send a request to the server (for example: get_name_of_id/1). Assuming, you have "get_name_of_id" function in the controller that echo-ing a name based on given id, you will get the name as response.
(Sorry if it sounds complicated). And then, the value of field-Name should be changed with that echoed name.
For more information about AJAX and JQuery, you can read https://stackoverflow.com/a/5004276/755319
I have done this what you want, it is really simple complete tutorial is on following link
http://www.grocerycrud.com/forums/topic/1087-updated-24112012-dependent-dropdown-library/
hope you will find it helpful

TableAdapter to return ONLY selected columns? (VS2008)

(VS2008) I'm trying to configure a TableAdapter in a Typed DataSet to return only a certain subset of columns from the main schema of the table on which it is based, but it always returns the entire schema (all columns) with blank values in the columns I have omitted.
The TableAdpater has the default Fill and GetData() methods that come from the wizard, which contain every column in the table, which is fine. I then added a new parameterized query method called GetActiveJobsByCustNo(CustNo), and I only included a few columns in the SQL query that I actually want to be in this table view.
But, again, it returns all the columns in the master table schema, with empty values for the columns I omitted.
The reason I am wanting this, is so I can just get a few columns back to use that table view with AutoGenerateColumns in an ASP.NET GridView. With it giving me back EVERY column i nthe schema, my presentation GridView contains way more columns that I want to show th user. And, I want to avoid have to declare the columns in the GridView.
When you add a new query to a given TableAdapter, it is going to assume the schema in which it is attached to, which is why you are getting blank values for the columns you don't want.
Since you mentioned having already created the procedure, what you need to do is use the Server Explorer to connect to the database and simply drag that stored procedure over into your XSD work area. What this will do is create a separate QueryAdapter that will have just the columns you specified (still strongly typed) and you can bind/interact with your GridView using that QueryAdapter instead.
Is the strongly typed dataset used in another query that returns all the rows from the table?
What you could do is create a dataview using the strongly typed dataset and expose a data table for your DataGridView.
I'm not sure what your requirements are totally, but this example should help you:
DataView dv = new DataView(ds.<Your_Table>);
// This will create a new data table with the same name,
// But with only two columns from the original table.
// This could then be bound to your data grid.
DataTable dt = dv.ToTable(false,
ds.<Your_Table>.<Your_Column1Column>.ColumnName,
ds.<Your_Table>.<Your_Column1Column>.ColumnName);
Just delete the columns you don't want at run-time before you bind to your Gridview. The underlying class is still just a DataTable after all.

Resources