DataTablesSrc icon indicating copy to clipboard operation
DataTablesSrc copied to clipboard

Improvement Idea

Open alexanderankin opened this issue 7 years ago • 6 comments

https://gist.github.com/alexanderankin/7da0.... (2 minute read)

^That implementation worked for me (aka it was 'good enough for who its for').

alexanderankin avatar Jun 03 '17 20:06 alexanderankin

Hi,

Thanks for posting this! I think that this is the sort of situation that a search plug-in would actually be ideally suited: https://datatables.net/manual/plug-ins/search .

DataTables avatar Jun 04 '17 19:06 DataTables

Well look, im not qualified to integrate these changes:

  • I don't know how your documentation system works
  • the argument names dont match up with the names on the function
    • im afraid to change that sort of thing because i don't know how your test system works
    • or how to run the tests
    • or documentation builder
  • the way its documented in the link you commented with is the way i tried it (i think) when i was doing that, and it didnt quite seem to work. I'll revisit it when i get the chance.

If someone who is active on this project notices it and agrees that this would be useful, power to them, I hope I did my best to document the changes (it even sorta looks like a patch, if you replace the double slashes with - signs and put a + on the line below). After I'm done my project ill try to do the settings thing again, but really - I'm not passionate enough about frontend development to invest the time into learning this project I think. Nobody would really see returns from that imo.

Do you think this change would be best as a plugin or would be merged into master?

alexanderankin avatar Jun 05 '17 02:06 alexanderankin

Just noticed that the arguments are just in hungarian notation in the doc comment. But I'm still really confused about the settings object... its supposed to contain all the fields that get passed in at construction time, right?

alexanderankin avatar Jun 05 '17 02:06 alexanderankin

Hi,

Sorry if sounded dismissive at all last night - that wasn't my intention! The idea with DataTables is that if a feature can be implemented with a plug-in, then it should be. If it proves to be a popular plug-in that it would be considered to be included in the core repo. The goal is to try and keep code that is only used in a few cases out of the core to keep it slimmer than it might otherwise be. This is a flexible rule of course, but I think its appropriate.

Your input is very welcome and I can see that filtering out rows with empty data would be useful. Custom plug-ins are more or less perfectly suited for this.

For example the following will check for a property called mySearchProperty on a row's data object. If it is falsy the row is filtered out. If it is truey the row is shown:

$.fn.dataTable.ext.search.push(
    function( settings, searchData, index, rowData, counter ) {
        return rowData.mySearchProperty ? true : false;
    }
);

Good point about the settings object. DataTables still uses Hungarian notation internally. It would have been a complete rewrite to address that in 1.10 (which introduced the camelCase init options and new API), for little benefit (other than making the code look a bit nicer). The settings object is internal to DataTables and doesn't have its API publicly documented.

its supposed to contain all the fields that get passed in at construction time, right?

No - it contains all of the settings for the DataTable. That might or might not reflect the initialisation options. Its basically a combination of the init options, defaults and any values that DataTables needs to calculate and store itself - e.g. scrollbar width. Its more than just the init options.

DataTables avatar Jun 05 '17 08:06 DataTables

sorry for that rude reply, I under-corrected for my mood after working all weekend. Thanks for taking the time to explain all the concepts, it's gonna take me a bit to wrap my head around all the repositories and plugin namespaces and stuff.

Here's to hoping I can rewrite into a plugin and remove the sed script to replace that line in my build script.

alexanderankin avatar Jun 05 '17 19:06 alexanderankin

I was the same after a stint on Sunday night :-).

Are you looking to actually remove the rows that have no data completely from the table rather than just filtering them out? Filtering them out suggests that the user would have the ability to show them at some point in future (perhaps via a UI widget).

If you don't want DataTables to see them at all, use the dataFilter option of the jQuery Ajax options. With that you can filter out the data you don't want and DataTables will never see it.

DataTables avatar Jun 06 '17 08:06 DataTables